﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Linq;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

namespace H2.NET.Web.Pages
{
    public partial class PMDC : TaskPage
    {
        #region 属性 Private
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }

        private string Department
        {
            get
            {
                return ViewState["Department"] == null ? "" : (string)ViewState["Department"];
            }
            set { ViewState["Department"] = value; }
        }

        private string PKG_PV
        {
            get
            {
                return ViewState["PKG_PV"] == null ? "" : (string)ViewState["PKG_PV"];
            }
            set { ViewState["PKG_PV"] = value; }
        }

        private string PKG_Cost
        {
            get
            {
                return ViewState["PKG_Cost"] == null ? "" : (string)ViewState["PKG_Cost"];
            }
            set { ViewState["PKG_Cost"] = value; }
        }

        #endregion

        #region 事件 页面加载
        protected void Page_Load(object sender, EventArgs e)
        {
            //UsersChoose1.isReturned = Assessment1.isReturned;
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;
                #region 初始化
                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
                {
                    try
                    {
                        string[] group = new string[] { "mdc_01_Planning", "mdc_01_Technical", "mdc_01_Markting", "mdc_01_Purchasing", "mdc_01_Logistics", "mdc_01_CCC", "mdc_01_Production", "mdc_01_QA", "mdc_01_Finance", "mdc_01_Packaging", "mdc_01_TradeMarketing", "mdc_01_BD", "mdc_01_TWMarketing", "mdc_01_TWSales", "mdc_01_TWTechnical", "mdc_01_TWPurchasing", "mdc_01_TWSupplyChain", "mdc_01_TWWarehouse", "mdc_01_TWPlanning", "mdc_01_TWFinance", "mdc_01_TWNBD", "mdc_01_HK" };
                        string[] group_in = new string[] { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
                        IsInGroup_s(UserAPI.UserName, group, ref group_in);
                        Department = group_in[0] == "1" ? "Planning" : (group_in[1] == "1" ? "Technical" : (group_in[2] == "1" ? "Markting" : (group_in[3] == "1" ? "Purchasing" : (group_in[4] == "1" ? "Logistics" : (group_in[5] == "1" ? "CCC" : (group_in[6] == "1" ? "Production" : (group_in[7] == "1" ? "QA" : (group_in[8] == "1" ? "Finance" : (group_in[9] == "1" ? "Packaging" : (group_in[10] == "1" ? "TradeMarketing" : (group_in[11] == "1" ? "BD" : (group_in[12] == "1" ? "TWMarketing" : (group_in[13] == "1" ? "TWSales" : (group_in[14] == "1" ? "TWTechnical" : (group_in[15] == "1" ? "TWPurchasing" : (group_in[16] == "1" ? "TWSupplyChain" : (group_in[17] == "1" ? "TWWarehouse" : (group_in[18] == "1" ? "TWPlanning" : (group_in[19] == "1" ? "TWFinance" : (group_in[20] == "1" ? "TWNBD" : "HK"))))))))))))))))))));
                        StoreAPI["Department"] = Department;
                    }
                    catch (Exception)
                    { }

                    if (TaskAPI.IsInitiate)
                    {
                        UserFullName.Text = UserAPI.UserFullName;
                        Time.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                        Distribute_B.Text = "blank123";
                    }

                    IList<mdc_Config> config = (mdc_Config.process == TaskAPI.Process & mdc_Config.step == TaskAPI.Step
                                             & (mdc_Config.department == Department | mdc_Config.department == "*")).List<mdc_Config>();
                    int i = 1;
                    Actions.Items.Clear();
                    foreach (mdc_Config c in config)
                    {
                        if (!string.IsNullOrEmpty(c.Action) && Actions.Items.FindByValue(c.Action) == null)
                        {
                            Actions.Items.Add(new ListItem(i.ToString() + ", " + c.Action, c.Action));
                            i++;
                        }
                    }
                    IList<string> productions_ = new List<string>();
                    productions_ = (m_Production.step == "Technical").List<m_Production>().Select(p => p.Production_Type).Distinct().ToList();

                    foreach (var pt in productions_)
                    {

                        Production.Items.Add(new ListItem(pt, pt));
                    }
                    if (Actions.Items.Count > 0)
                    {
                        Actions.Items[0].Selected = true;
                    }

                }
                InitDistribute();
                //InitTabTags();
                //各审核环节

                if (!TaskAPI.IsInitiate)
                {
                    mdc_MDC mdc = (mdc_MDC.process == TaskAPI.Process & mdc_MDC.incident == TaskAPI.Incident).ListFirst<mdc_MDC>();
                    if (mdc != null)
                    {
                        UserFullName.Text = mdc.UserFullName;
                        ApplicatorNo.Text = mdc.ApplicationNo;

                        if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
                        {
                            Actions.SelectedValue = mdc.Actions;
                            Production.SelectedValue = mdc.Production;
                            //Distribute.SelectedValue = mdc.Distribute;

                            //zph增加p-plant退回时显示distribute功能
                            if (TaskAPI.Process == "P-Plant Extend Application")
                            {
                                SetDropDownListValue(Distribute, mdc.Distribute);
                            }
                            else
                            {
                                Distribute.SelectedValue = mdc.Distribute;
                            }

                        }
                        else
                        {
                            Actions.Items.Clear();
                            Actions.Items.Add(new ListItem("1, " + mdc.Actions, mdc.Actions));
                            Production.Items.Add(new ListItem(mdc.Production, mdc.Production));
                            Distribute.Items.Add(new ListItem("1, " + mdc.Distribute, mdc.Distribute));

                        }


                        StoreAPI["Department"] = mdc.Department;
                        Department = mdc.Department;


                        Production.SelectedValue = mdc.Production;
                        //Distribute.SelectedValue = mdc.Distribute;

                        //zph增加p-plant退回时显示distribute功能

                        if (TaskAPI.Process == "P-Plant Extend Application")
                        {
                            SetDropDownListValue(Distribute, mdc.Distribute);
                        }
                        else
                        {
                            Distribute.SelectedValue = mdc.Distribute;
                        }



                        DrpPriority.SelectedValue = mdc.DrpPriority;
                        Distribute_B.Text = mdc.Distribute;
                        NPL_Sefi_BOM.SelectedValue = mdc.NPL_Sefi_BOM;
                        Product_Line.SelectedValue = mdc.Product_Line;
                        Try_Product.SelectedValue = mdc.Try_Product;
                        Channel.SelectedValue = mdc.Channel;
                        Change_KPL.SelectedValue = mdc.Change_KPL;
                        Affect_APO.SelectedValue = mdc.Affect_APO;

                        Change_Modification.SelectedValue = mdc.Change_Modification;
                        Code_Selected.Checked = mdc.Code_Selected == "1";
                        BOM_Selected.Checked = mdc.BOM_Selected == "1";
                        PKG_PV = mdc.User_PV;
                        PKG_Cost = mdc.User_Finance;
                        Sefi_Bom.Checked = mdc.Sefi_Bom == "1";
                        INP.Checked = mdc.INP == "1";
                        PackCode_Selected.Checked = mdc.IsPackcode == "1";
                        SefiCode_Selected.Checked = mdc.IsSefiCode == "1";
                        DrpPriority.SelectedValue = mdc.DrpPriority;
                        #region NPL Master Data Application 加载选中工厂状态
                        if (TaskAPI.Process == "NPL Master Data Application")
                        {
                            DataTable db = new DataTable();
                            db = GetSelect(this.TaskAPI.Incident, this.TaskAPI.Process);
                            if (db.Rows.Count > 0)
                            {
                                mdc.IsSH_Selected = db.Rows[0]["IsSH_Selected"].ToString();
                                mdc.IsGZ_Selected = db.Rows[0]["IsGZ_Selected"].ToString();
                                mdc.IsLF_Selected = db.Rows[0]["IsLF_Selected"].ToString();
                                mdc.IsRadionList_NPL = db.Rows[0]["IsRadionList_NPL"].ToString();
                                SH_Selected.Checked = mdc.IsSH_Selected == "1";
                                GZ_Selected.Checked = mdc.IsGZ_Selected == "1";
                                LF_Selected.Checked = mdc.IsLF_Selected == "1";
                                if (TaskAPI.Step != "Production Site Select")
                                {

                                    RadionList_NPL.Enabled = false;
                                    RadionList_NPL.SelectedValue = mdc.IsRadionList_NPL;
                                }
                            }
                        }
                        #endregion

                        if (TaskAPI.Process == "HK ADVE Code Application")
                        {
                            rd_HK_ADVE_Biz_Type.SelectedIndex = Convert.ToInt16(mdc.rd_HK_ADVE_Biz_Type);
                        }
                        if (TaskAPI.Process == "TW Raw Code Application")
                        {
                            rd_Raw_Code.SelectedIndex = Convert.ToInt16(mdc.rd_Raw_Code);
                        }

                        Time.Text = mdc.Time.ToString("yyyy-MM-dd HH:mm:ss");
                        IsShowSAPCode.Text = mdc.IsShowSAPCode == "C" ? (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit ? "C" : "S") : "";
                    }


                }
                #endregion

                #region 审批意见
                switch (TaskAPI.Step)
                {
                    case "Fill in the request":
                        if (TaskAPI.Process == "TJO Base Code Application")
                        {
                            if (TaskAPI.IsBeginStep && !TaskAPI.IsInitiate)
                            {
                                Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                                Assessment1.Option.Add(new t_AssessmentOption("Cancel", "2", false));
                                Assessment1.Option.Add(new t_AssessmentOption("来样是否收到?", "3", false));

                            }
                            else
                            {
                                Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                                Assessment1.Option.Add(new t_AssessmentOption("来样是否收到?", "3", false));
                            }
                        }
                        break;
                    case "PKG Planning":
                    case "PKG Purchasing":
                    case "PKG Logistic":
                    case "PKG QA":
                    case "DMO Material Maintain":
                    case "Technical PV":
                    case "Finance Test Run":
                    case "Technical Confirm & PV":
                    case "Manager Approve":
                    case "Tech confirm and create PV":

                    case "Purchasing Manager Approve":

                    case "Technical Confirm PV":
                    case "Planning":
                    case "SH Planning":
                    case "LF Planning":
                    case "GZ Planning":
                    case "Purchasing":
                    case "Trade Planning":
                    case "Trade Purchasing":
                    case "Logistic":
                    case "QA":
                    case "QC":
                    case "Planning Determination":
                    case "QA Approve":
                    case "Technical Manager":
                    case "Trade Manager Approve":
                    case "Trade Marketing Manager":
                    case "Finance Manager Approve":
                    case "Line Manager Approve":
                    case "QA Manager":
                    case "Production PI":
                    case "QA Check Pack Ins Plan":
                    case "QA Confirm Barcode":
                    //Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                    //Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                    //break;
                    case "Applicant Confirm":
                    case "Finance Run Cost":
                    case "DMO Change Status":
                    case "DMO Approve":
                    case "DMO BOM Approve":
                    case "DMO Maintain":
                    case "DMO BOM Maintain":
                    case "HSE":
                    case "HSE Approve":
                    case "Technical Check":
                    case "Technical":
                    case "Technical Material":
                    case "Technical Confirm Price":
                    case "Technical BOM":
                    case "Technical Confirm":
                    case "QA Supervisor":
                    case "QA Check Barcode":
                    case "Line Manager":
                    case "Finance":
                    case "Finance Run Cost2":
                    case "Finance Run Cost3":
                    case "Finance Run Cost4":
                    case "Finance Run Cost SH":
                    case "Finance Run Cost GZ":
                    case "Finance Run Cost LF":
                    case "Marketing Add Data":
                    case "Logistic Add Data":
                    case "Purchasing Add Data":
                    case "LAM Run Price":
                    case "Run ICD Price":
                    case "Run ICD Price2":
                    case "DMO Run SM35":
                    case "LF Finance Run Cost":
                    case "Production PV":
                    case "Production PV2":
                    case "Production PV3":
                    case "Production PV4":
                    case "Production PV GZ":
                    case "Production PV SH":
                    case "Production PV LF":
                    case "Production PV OEM":
                    case "DMO Change Status ZF":
                    case "DMO Change ZF":
                    case "HK Finance":
                    case "DMO Change Status ZG":
                    //zph添加DMO Change Status to ZG
                    case "DMO Change Status to ZG":
                    case "Finance Manager":
                    case "DMO Check":
                    case "DMO BOM Check":
                    case "HK Finance KKPAN":
                    case "HK KKPan":
                    case "Provide ICD Price":
                    case "Provide HK ICD Price":
                    case "DMO Check Price":
                    case "DMO Maintain ICD Price":
                    case "HK Marketing":
                    case "QA Maintain Barcode":
                    case "DMO Maintain EOE":
                    case "Logistic WM View ":
                    case "Marketing":
                    case "Technical Create PV":
                    case "CCC Confirm Sales Order":
                    case "Technical Confirm RMC":
                    case "Sample is received":
                    //TB 添加DMO流程
                    case "OEM Planning":
                    case "SH Production":
                    case "OEM Production":
                    case "GZ Production":
                    case "LF Production":
                    //TB 添加NPL流程新节点
                    case "Pro PD Plant Extend Retail":
                    case "Pro PD Plant Extend MTO":
                    case "Pro PD Plant Extend Project":
                    case "OEM Plant Extend Retail":
                    case "OEM Plant Extend Project":
                    case "Pack Extend":
                    case "RDC Plant Extend":
                    case "Production Site Select":
                    case "Production Confirm PV":
                    case "Retail Manager":
                    case "Project Manager":
                    case "Pre Deco Manager":
                    case "Woodcare Manager":
                    case "HPC Manager":
                    case "Retial Switch BOM":
                    case "Project Switch BOM":
                    case "Pre Deco Switch BOM":
                    case "Woodcare Switch BOM":
                    case "HPC Switch BOM":
                    case "Retial Lock BOM":
                    case "Project Lock BOM":
                    case "Pre Deco Lock BOM":
                    case "Woodcare Lock BOM":
                    case "HPC Lock BOM":
                    case "DMO Lock PV":
                    case "Retial Planning Place Order":
                    case "Project Planning Place Order":
                    case "PreDeco Planning Place Order":
                    case "Woodcare Planing Place Order":
                    case "HPC Planning Place Order":

                        //case "Confirm Pack Version":
                        Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                        Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));

                        if ((TaskAPI.Process == "HK Trade Code Application" || TaskAPI.Process == "HK ADVE Code Application") && TaskAPI.Step == "DMO Check")
                        {
                            Assessment1.Option.Add(new t_AssessmentOption("HK Finance", "3", false));
                        }

                        if (TaskAPI.Process == "HK Fini Code Application" && TaskAPI.Step == "DMO Check")
                        {
                            Assessment1.Option.Add(new t_AssessmentOption("Finance Run Cost", "3", false));
                            Assessment1.Option.Add(new t_AssessmentOption("HK Finance", "4", false));
                        }
                        //if (TaskAPI.Process == "Pack Code Application" && TaskAPI.Step == "DMO Approve")
                        //{
                        //    Assessment1.Option.Add(new t_AssessmentOption("Confirm Pack Version", "3", false));
                        //}
                        break;

                    case "Production":
                    case "Logistic WM View":
                    case "RM":
                    case "DMO Maintain Price":
                    case "HK KKPAN":
                        Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                        break;
                }
                #endregion

                #region 设置控件禁启用
                bool flg = ((TaskAPI.IsInitiate || TaskAPI.IsBeginStep) && TaskAPI.IsAllowSubmit) ? true : false;
                switch (Process)
                {
                    case "MTO Base Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "MTO Template Data Collection":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Product Grouphiera Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TJO Base Code Application":
                        SetVisible(!TaskAPI.IsInitiate && TaskAPI.IsBeginStep, Cancel);
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        //Cancel.Attributes.Add("onclick","return confirm ('确认取消Request吗？'); ");
                        break;
                    case "PKG Sefi Code BOM Application":
                        //if (Actions.SelectedValue == "Revision")
                        //{
                        SetVisible(true, Code_Selected, BOM_Selected);
                        //}
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
                        {
                            SetEnable(true, Code_Selected, BOM_Selected);
                        }
                        else
                        {
                            SetEnable(false, Code_Selected, BOM_Selected);
                        }
                        break;
                    case "PKG Fini Code BOM Application":
                        //if (Actions.SelectedValue == "Revision")
                        //{
                        SetVisible(true, Code_Selected, BOM_Selected);
                        //}
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
                        {
                            SetEnable(true, Code_Selected, BOM_Selected);
                        }
                        else
                        {
                            SetEnable(false, Code_Selected, BOM_Selected);
                        }
                        break;
                    case "PKG Ins Char Plan Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Fini Bom Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "NPL Master Data Application":
                        if (TaskAPI.Step == "Technical" || TaskAPI.Step == "Technical Manager" || TaskAPI.Step == "Technical BOM" || TaskAPI.Step == "Logistic" || TaskAPI.Step == "Production Site Select" || TaskAPI.Step == "OEM Plant Extend Retail" || TaskAPI.Step == "OEM Plant Extend Project" || TaskAPI.Step == "RDC Plant Extend" || TaskAPI.Step == "Pro PD Plant Extend Retail" || TaskAPI.Step == "Pro PD Plant Extend MTO" || TaskAPI.Step == "Pro PD Plant Extend Project" || TaskAPI.Step == "OEM Plant Extend Retail" || TaskAPI.Step == "Trade Planning")
                        {
                            PackCode_Selected.Visible = false;
                        }
                        else
                        {
                            PackCode_Selected.Visible = true;
                        }
                        if (TaskAPI.Step == "Fill in the request" || TaskAPI.Step == "Purchasing" || TaskAPI.Step == "Production Site Select" || TaskAPI.Step == "Pack Extend" || TaskAPI.Step == "Trade Purchasing" || TaskAPI.Step == "Trade Planning")
                        {
                            SefiCode_Selected.Visible = false;
                        }
                        else
                        {
                            SefiCode_Selected.Visible = true;
                        }
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L);

                        if (TaskAPI.Step == "Fill in the request" || TaskAPI.Step == "Technical" || TaskAPI.Step == "Logistic" || TaskAPI.Step == "Purchasing" || TaskAPI.Step == "Trade Purchasing" || TaskAPI.Step == "Trade Planning")
                        {
                            SetVisible(false, SH_Selected, GZ_Selected, LF_Selected);
                        }
                        else
                        {
                            SetVisible(true, SH_Selected, GZ_Selected, LF_Selected);
                        }
                        if (TaskAPI.Step != "Production Site Select" || TaskAPI.Step != "Pack Extend" || TaskAPI.Step != "Pro PD Plant Extend MTO" || TaskAPI.Step != "Pro PD Plant Extend Project" || TaskAPI.Step != "Pro PD Plant Extend Retail" || TaskAPI.Step != "OEM Plant Extend Retail" || TaskAPI.Step != "OEM Plant Extend Project" || TaskAPI.Step != "RDC Plant Extend" || TaskAPI.Step != "Trade Planning")
                        {
                            SetVisible(false, RadionList_NPL);
                        }
                        if (TaskAPI.Step == "Production Site Select")
                        {
                            RadionList_NPL.Visible = SH_Selected.Checked && SH_Selected.Visible == true;
                        }
                        break;
                    case "Return Goods Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "HK Fini Code Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "HK Trade Code Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Sefi BomIP Application":
                        SetVisible(false, Code_Selected, BOM_Selected, Change_Modification_L, Change_Modification, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Formula Switch Process":
                        SetVisible(false, Code_Selected, BOM_Selected, Change_Modification_L, Change_Modification, NPL_Sefi_BOM_L, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Actions, Actions_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(true, Distribute, Distribute_L);
                        break;
                    case "QA Inspection Plan":
                        SetVisible(false, Code_Selected, BOM_Selected, NPL_Sefi_BOM_L, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(true, Distribute, Distribute_L);
                        break;
                    case "PKG RAW Code Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "PKG PACK Code Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "HK ADVE Code Application":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(true, rd_HK_ADVE_Biz_Type);
                        SetEnable(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit, rd_HK_ADVE_Biz_Type);
                        break;
                    case "Raw Code Pack Size Change":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "New Raw Material Introducing":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Global New Raw Material-CN":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L, DrpPriority, DrpPriority_L);
                        break;
                    case "Global New Raw Material-TW":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L, DrpPriority, DrpPriority_L);
                        break;
                    case "Sefi Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Fini Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Channel, Channel_L);
                        SetVisible(true, DrpPriority_L, DrpPriority);
                        break;
                    case "Raw Code Extend Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Raw Code Change Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Pack Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "D-Plant Extend Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "ADVE Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L);
                        break;
                    case "Raw Inspection Plan-Tech":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Inspection Plan":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;

                    case "HK-TJO Base Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "HK-MTO Base Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Logistics-Planning Change":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Barcode Scan Master":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Actions, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "Formula Change Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "P-Plant Extend Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(true, PackCode_Selected, SefiCode_Selected, Production_L, Production);
                        break;
                    case "D-plant Determination":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        //SetVisible(true, PackCode_Selected, SefiCode_Selected);
                        break;
                    case "Trade Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "HK NPL Master Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(TaskAPI.Step == "Technical", SefiCode_Selected);
                        //SetVisible(true, PackCode_Selected);
                        //SetVisible(!TaskAPI.IsBeginStep, SefiCode_Selected);
                        break;
                    case "HK-NPL Pack Size Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW ADVE Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW Trade Code Application-DECO":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW Trade Code Application-PKG":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;

                    case "TW Group-Hierarchy-Cluster":
                        SetVisible(false, Distribute, Distribute_L, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW New Raw Material Creation":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW Pack Material Maintenance":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW Fini Bom Maintenance":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW NPL Application-PKG":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        //SetVisible(TaskAPI.Step == "PKG Purchasing" && TaskAPI.IsAllowSubmit, PackCode_Selected);
                        SetVisible(TaskAPI.Step != "Fill in the request" && TaskAPI.Step != "PKG Planning", PackCode_Selected);
                        SetVisible(true, SefiCode_Selected);
                        break;
                    case "TW NPL Application-DECO":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(TaskAPI.Step != "Fill in the request", PackCode_Selected);
                        SetVisible(TaskAPI.Step != "Fill in the request" && TaskAPI.Step != "Purchasing", SefiCode_Selected);
                        break;
                    case "TW Inspection Plan Maintenance":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Distribute_L, Distribute, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(true, IP_Selected, Qual_Selected, Quan_Selected);
                        SetEnable(TaskAPI.Step == "Fill in the request" && TaskAPI.IsAllowSubmit, IP_Selected, Qual_Selected, Quan_Selected);
                        break;
                    case "TW Sefi Bom-IP Maintenance":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;

                    case "TW MTO Application-DECO":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, DrpPriority_L, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, DrpPriority, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW MTO Application-PKG":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, DrpPriority_L, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, DrpPriority, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW Raw Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        SetVisible(true, Distribute_L, Distribute, rd_Raw_Code);
                        //SetVisible(true, SefiCode_Selected, PackCode_Selected);
                        //BOM_Selected.Text = "Raw For Sale";
                        //Code_Selected.Text = "Raw Code";
                        //if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
                        //{
                        //    SetEnable(true, Code_Selected, BOM_Selected);
                        //}
                        //else
                        //{
                        //    SetEnable(false, Code_Selected, BOM_Selected);
                        //}
                        SetEnable(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit, rd_Raw_Code);
                        break;
                    //PackCode_Selected.Checked = true;
                    //SefiCode_Selected.Checked = false;
                    case "TW SERV Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW SEFI Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;
                    case "TW FINI Code Application":
                        SetVisible(false, NPL_Sefi_BOM_L, Change_Modification_L, Change_Modification, Code_Selected, BOM_Selected, NPL_Sefi_BOM, Sefi_Bom_L, INP_L, Sefi_Bom, INP, Product_Line, Product_Line_L, Try_Product, Try_Product_L, Change_KPL, Change_KPL_L, Affect_APO, Affect_APO_L, Channel, Channel_L);
                        break;

                }

                SetEnable(flg, Actions, Distribute, NPL_Sefi_BOM, Change_Modification, PackCode_Selected, Sefi_Bom, INP, Product_Line, Try_Product, Change_KPL, DrpPriority, Affect_APO, Channel);
                if (TaskAPI.Process == "NPL Master Data Application")
                {
                    SetEnable((TaskAPI.Step == "Technical" || TaskAPI.Step == "Production Site Select") && TaskAPI.IsAllowSubmit, SefiCode_Selected);
                    SetEnable(TaskAPI.Step == "Production Site Select" && TaskAPI.IsAllowSubmit, SH_Selected, GZ_Selected, LF_Selected);
                }
                if (TaskAPI.Process == "TW NPL Application-PKG")
                {
                    SetEnable(TaskAPI.Step == "Fill in the request" && TaskAPI.IsAllowSubmit, SefiCode_Selected);
                    SetEnable(TaskAPI.Step == "PKG Purchasing" && TaskAPI.IsAllowSubmit, PackCode_Selected);

                }
                if (TaskAPI.Process == "TW NPL Application-DECO")
                {
                    SetEnable(TaskAPI.Step == "Technical" && TaskAPI.IsAllowSubmit, SefiCode_Selected);
                    SetEnable(TaskAPI.Step == "Purchasing" && TaskAPI.IsAllowSubmit, PackCode_Selected);
                }
                //if (TaskAPI.Process == "HK NPL Master Applicationn")
                //{
                //    SetEnable(TaskAPI.Step != "Technical", SefiCode_Selected);
                //}
                if (TaskAPI.Process == "P-Plant Extend Application")
                {
                    SetEnable(TaskAPI.Step == "Fill in the request" && TaskAPI.IsAllowSubmit, SefiCode_Selected);
                }
                if (TaskAPI.Process == "TW Raw Code Application")
                {
                    SetEnable(TaskAPI.Step == "Fill in the request" && TaskAPI.IsAllowSubmit, PackCode_Selected, SefiCode_Selected);
                }
                //SetEnable((TaskAPI.Process == "NPL Master Data Application" || TaskAPI.Process == "P-Plant Extend Application") && TaskAPI.Step == "Technical" && TaskAPI.IsAllowSubmit, SefiCode_Selected);
                SetVisible(!TaskAPI.IsInitiate, No);
                SetVisible((!TaskAPI.IsInitiate && TaskAPI.IsAllowSubmit) || (TaskAPI.IsInitiate && (MM1.Visible || MM2.Visible
                                                      || TWIP.Visible || this.HKNPL.Visible || DD1.Visible || DD2.Visible || DD3.Visible || MM3.Visible || MM4.Visible || BOM1.Visible || BOM2.Visible || INP1.Visible || BAR1.Visible || CCC1.Visible || TJO1.Visible || PR1.Visible || PR2.Visible || QUAL.Visible || QUAN.Visible || PLALOG1.Visible || SCAN1.Visible || FORMU1.Visible || FORMU2.Visible || SHMM1.Visible || SHMM2.Visible || SHMM3.Visible || SHMM4.Visible || BOM3.Visible)), Send, Split);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;

                PMDCAttachment1.AllowUpload = TaskAPI.IsAllowSubmit;
                PMDCAttachment1.AllowDelete = TaskAPI.IsAllowSubmit;
                switch (TaskAPI.Process)
                {
                    case "TW NPL Application-DECO":
                    case "TW NPL Application-PKG":
                    case "NPL Master Data Application":
                        //case "TW Raw Code Application":
                        PackCode_Selected.Checked = ((object[])TaskAPI["IsPackCode"])[0].ToString() == "0" ? false : true;
                        SefiCode_Selected.Checked = ((object[])TaskAPI["IsSefiCode"])[0].ToString() == "0" ? false : true;
                        break;
                    case "P-Plant Extend Application":
                        PackCode_Selected.Checked = ((object[])TaskAPI["IsPackCode"])[0].ToString() == "0" ? false : true;
                        SefiCode_Selected.Checked = ((object[])TaskAPI["IsSefiCode"])[0].ToString() == "0" ? false : true;
                        break;
                    case "TW Inspection Plan Maintenance":
                        IP_Selected.Checked = ((object[])TaskAPI["IsIpCode"])[0].ToString() == "0" ? false : true;
                        Quan_Selected.Checked = ((object[])TaskAPI["IsQuanCode"])[0].ToString() == "0" ? false : true;
                        Qual_Selected.Checked = ((object[])TaskAPI["IsQualCode"])[0].ToString() == "0" ? false : true;


                        break;
                    //case "HK ADVE Code Application":
                    //    rd_HK_ADVE_Biz_Type.SelectedIndex = m;
                    //    break;
                }
                #endregion

                InitTabStatus();
            }

            //Actions切换
            string actions = Request.Form["__EVENTTARGET"];
            if (!string.IsNullOrEmpty(actions) && actions == Actions.ID)
            {
                InitTabStatus();
            }


            UsersChoose1.MDCActions = Actions.SelectedValue;

            //For Npl
            SetFiniBomType();

            if (TaskAPI.Process == "HK ADVE Code Application")
            {
                SetADVETAB(e);
            }
            if (TaskAPI.Process == "TW Raw Code Application")
            {
                SetRawTAB(e);
            }
            if (TaskAPI.Process == "TW SEFI Code Application")
            {
                SetSefiTAB(e);
            }
        }
        #endregion

        #region 事件 Tabs
        protected void MM_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }
            #region 初始化
            SetVisible(false, PP29, PP28, PP27, PP26, PP25, PP24, PP23, PP20, PP21, PP22, PP1, PP2, PP3, PP18, PP4, PP5, PP6, PP7, PP8, PP9, PP10, PP11, PP12, PP13, PP14, PP15, PP16, PP17);
            MM1.CssClass = "tabs1";
            MM2.CssClass = "tabs1";
            MM3.CssClass = "tabs1";
            MM4.CssClass = "tabs1";
            BOM1.CssClass = "tabs1";
            BOM2.CssClass = "tabs1";
            INP1.CssClass = "tabs1";
            BAR1.CssClass = "tabs1";
            CCC1.CssClass = "tabs1";
            TJO1.CssClass = "tabs1";
            PR1.CssClass = "tabs1";
            PR2.CssClass = "tabs1";
            QUAL.CssClass = "tabs1";
            QUAN.CssClass = "tabs1";
            PLALOG1.CssClass = "tabs1";
            SCAN1.CssClass = "tabs1";
            FORMU1.CssClass = "tabs1";
            FORMU2.CssClass = "tabs1";
            DD1.CssClass = "tabs1";
            DD2.CssClass = "tabs1";
            DD3.CssClass = "tabs1";
            HKNPL.CssClass = "tabs1";
            TWIP.CssClass = "tabs1";

            //TB添加
            SHMM1.CssClass = "tabs1";
            SHMM2.CssClass = "tabs1";
            SHMM3.CssClass = "tabs1";
            SHMM4.CssClass = "tabs1";
            BOM3.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "MM1":
                    MM1.CssClass = "tabs2";
                    PP1.Visible = true;
                    break;
                case "MM2":
                    MM2.CssClass = "tabs2";
                    PP2.Visible = true;
                    break;
                case "MM3":
                    MM3.CssClass = "tabs2";
                    PP3.Visible = true;
                    break;
                case "MM4":
                    MM4.CssClass = "tabs2";
                    PP18.Visible = true;
                    break;
                case "BOM1":
                    BOM1.CssClass = "tabs2";
                    PP4.Visible = true;
                    break;
                case "BOM2":
                    BOM2.CssClass = "tabs2";
                    PP8.Visible = true;
                    break;
                case "INP1":
                    INP1.CssClass = "tabs2";
                    PP5.Visible = true;
                    break;
                case "BAR1":
                    BAR1.CssClass = "tabs2";
                    PP6.Visible = true;
                    break;
                case "CCC1":
                    CCC1.CssClass = "tabs2";
                    PP7.Visible = true;
                    break;
                case "PR1":
                    PR1.CssClass = "tabs2";
                    PP9.Visible = true;
                    break;
                case "PR2":
                    PR2.CssClass = "tabs2";
                    PP10.Visible = true;
                    break;
                case "QUAL":
                    QUAL.CssClass = "tabs2";
                    PP11.Visible = true;
                    break;
                case "QUAN":
                    QUAN.CssClass = "tabs2";
                    PP12.Visible = true;
                    break;
                case "TJO1":
                    TJO1.CssClass = "tabs2";
                    PP13.Visible = true;
                    break;
                case "PLALOG1":
                    PLALOG1.CssClass = "tabs2";
                    PP14.Visible = true;
                    break;
                case "SCAN1":
                    SCAN1.CssClass = "tabs2";
                    PP15.Visible = true;
                    break;
                case "FORMU1":
                    FORMU1.CssClass = "tabs2";
                    PP16.Visible = true;
                    break;
                case "FORMU2":
                    FORMU2.CssClass = "tabs2";
                    PP17.Visible = true;
                    break;
                case "DD1":
                    DD1.CssClass = "tabs2";
                    PP20.Visible = true;
                    break;
                case "DD2":
                    DD2.CssClass = "tabs2";
                    PP21.Visible = true;
                    break;
                case "DD3":
                    DD3.CssClass = "tabs2";
                    PP22.Visible = true;
                    break;
                case "HKNPL":
                    HKNPL.CssClass = "tabs2";
                    PP23.Visible = true;
                    break;
                case "TWIP":
                    TWIP.CssClass = "tabs2";
                    PP24.Visible = true;
                    break;
                //TB 添加
                case "SHMM1":
                    SHMM1.CssClass = "tabs2";
                    PP25.Visible = true;
                    break;
                case "SHMM2":
                    SHMM2.CssClass = "tabs2";
                    PP26.Visible = true;
                    break;
                case "SHMM3":
                    SHMM3.CssClass = "tabs2";
                    PP27.Visible = true;
                    break;
                case "SHMM4":
                    SHMM4.CssClass = "tabs2";
                    PP28.Visible = true;
                    break;
                case "BOM3":
                    BOM3.CssClass = "tabs2";
                    PP29.Visible = true;
                    break;
            }
            #endregion

            SetFiniBomType();
        }
        #endregion

        #region 事件 Actions
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            InitTabTags();
            TabBom1.BomActions = Actions.SelectedValue;
            TabBom1.InitControls();
            TabMaterial1.MMActions = Actions.SelectedValue;
            TabMaterial1.InitControls();
            TabMaterial2.MMActions = Actions.SelectedValue;
            TabMaterial2.InitControls();
            TabMaterial3.MMActions = Actions.SelectedValue;
            TabMaterial3.InitControls();
            TabMaterial4.MMActions = Actions.SelectedValue;
            TabMaterial4.InitControls();
            Detemination1_1.InitControls();
            Detemination1_2.InitControls();
            Detemination1_3.InitControls();
            TabHKNpl1.InitControls();
            TWTabInsPlan1.InitControls();

            //TB添加
            TabBom3.BomActions = Actions.SelectedValue;
            TabBom3.InitControls();
            TabMaterial5.MMActions = Actions.SelectedValue;
            TabMaterial5.InitControls();
            TabMaterial6.MMActions = Actions.SelectedValue;
            TabMaterial6.InitControls();
            TabMaterial7.MMActions = Actions.SelectedValue;
            TabMaterial7.InitControls();
            TabMaterial8.MMActions = Actions.SelectedValue;
            TabMaterial8.InitControls();
            if (TaskAPI.Process == "HK ADVE Code Application")
            {
                SetADVETAB(e);
            }
            if (TaskAPI.Process == "TW Raw Code Application")
            {
                SetRawTAB(e);

            }
            if (TaskAPI.Process == "TW SEFI Code Application")
            {
                SetSefiTAB(e);
            }

            //if (TaskAPI.Process == "TW Fini Bom Maintenance") 
            //{
            //    if (Actions.SelectedItem.Text == "1, Creation")
            //    {
            //        if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            //        {
            //            SetForeColor(Color.Blue, (Page as PMDC).TabBom1.TW_Alternative_Bom_L, (Page as PMDC).TabBom1.TW_Fini_SAP_Code_L, (Page as PMDC).TabBom1.TW_BoM_status_L, (Page as PMDC).TabBom1.TW_Base_quantity_L);
            //        }
            //        else
            //        {
            //            SetForeColor(Color.Black, (Page as PMDC).TabBom1.TW_Alternative_Bom_L, (Page as PMDC).TabBom1.TW_Fini_SAP_Code_L, (Page as PMDC).TabBom1.TW_BoM_status_L, (Page as PMDC).TabBom1.TW_Base_quantity_L);
            //        }
            //    }

            //    if (Actions.SelectedItem.Text == "2, Revision")
            //    {
            //        if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            //        {
            //            SetForeColor(Color.Blue, (Page as PMDC).TabBom1.TW_Fini_SAP_Code_L);
            //        }
            //        else
            //        {
            //            SetForeColor(Color.Black, (Page as PMDC).TabBom1.TW_Alternative_Bom_L, (Page as PMDC).TabBom1.TW_Fini_SAP_Code_L, (Page as PMDC).TabBom1.TW_BoM_status_L, (Page as PMDC).TabBom1.TW_Base_quantity_L);
            //        }
            //    }
            //}
            if (TaskAPI.Process == "TW Trade Code Application-DECO")
            {
                if (Actions.SelectedItem.Text == "1, Creation")
                {
                    SetVisible(true, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location_L);
                    SetVisible(false, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location_1, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location_1_L);
                }
                else
                {
                    SetVisible(false, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location_L);
                    SetVisible(true, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location_1, (Page as PMDC).TabMaterial1.Planning1.PLA_Storage_Location_1_L);
                }
            }
            if (TaskAPI.Process == "TW Pack Material Maintenance")
            {
                if (Actions.SelectedItem.Text == "1, Creation" || Actions.SelectedItem.Text == "3, Extend")
                {
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Do_Not_Cost.Checked = false;
                    (Page as PMDC).TabMaterial1.Finance1.FIN_With_Qty_Structure.Checked = true;
                    SetForeColor(Color.Blue, (Page as PMDC).TabMaterial1.Technical1.TEC_Active_L);
                    SetEnable(false, (Page as PMDC).TabMaterial1.Finance1.FIN_Do_Not_Cost, (Page as PMDC).TabMaterial1.Finance1.FIN_With_Qty_Structure);
                    SetForeColor(Color.Orange, (Page as PMDC).TabMaterial1.Finance1.FIN_Do_Not_Cost_L, (Page as PMDC).TabMaterial1.Finance1.FIN_With_Qty_Structure_L);
                }
                else
                {
                    SetEnable(true, (Page as PMDC).TabMaterial1.Finance1.FIN_Do_Not_Cost, (Page as PMDC).TabMaterial1.Finance1.FIN_With_Qty_Structure);
                    SetForeColor(Color.Black, (Page as PMDC).TabMaterial1.Finance1.FIN_Do_Not_Cost_L, (Page as PMDC).TabMaterial1.Finance1.FIN_With_Qty_Structure_L);
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Do_Not_Cost.Checked = false;
                    (Page as PMDC).TabMaterial1.Finance1.FIN_With_Qty_Structure.Checked = false;

                }
            }
            #region 控制textbox 的enable属性
            if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }

                    }

                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }

                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Marketing1.MKT_P1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Marketing1.MKT_P1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Marketing1.MKT_P1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Marketing1.MKT_P1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial1.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit) && TaskAPI.Step != "Planning" && TaskAPI.Step != "SH Planning" && TaskAPI.Step != "GZ Planning" && TaskAPI.Step != "LF Planning" && TaskAPI.Step != "HK Marketing")
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Planning1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit) && TaskAPI.Step != "Technical")
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit) && TaskAPI.Step != "Marketing" && TaskAPI.Step != "Marketing Add Data" && TaskAPI.Step != "HK Marketing")
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }

                foreach (Control cr in (Page as PMDC).TabMaterial1.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Marketing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Marketing1.MKT_P2.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        };
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit))
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.CA1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit))
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Finance1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit) && TaskAPI.Step != "Technical")
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Technical1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit) && TaskAPI.Step != "Logistc" && TaskAPI.Step != "Logistic Add Data")
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Logistics1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit) && TaskAPI.Step != "Purchasing" && TaskAPI.Step != "Purchasing Add Data")
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.Purchasing1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            }
            if ((!TaskAPI.IsBeginStep || !TaskAPI.IsAllowSubmit))
            {
                foreach (Control cr in (Page as PMDC).TabMaterial1.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial2.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial3.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in (Page as PMDC).TabMaterial4.SAPCode1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
            #endregion
            }

        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                
                #region 数据验证
                if (string.IsNullOrEmpty(Assessment1.Assessment.Opinion) || Assessment1.Assessment.Opinion == "1")   //如果是退回的情况，不存在验证
                {
                    List<string> valid = new List<string>();
                    valid.AddRange(this.DataValidation());
                    valid.AddRange(this.DataValidations());
                    if (TaskAPI.Process != "MTO Template Data Collection")
                    {
                        if ((PackCode_Selected.Checked && PackCode_Selected.Visible && TaskAPI.Process != "NPL Master Data Application") || (TaskAPI.Process != "TW NPL Application-DECO" && TaskAPI.Process != "TW NPL Application-PKG" && TaskAPI.Process != "HK NPL Master Application" && TaskAPI.Process != "NPL Master Data Application" && TaskAPI.Process != "P-Plant Extend Application"))
                        {
                            valid.AddRange(TabMaterial1.DataValidation());
                        }
                        if ((SefiCode_Selected.Checked && SefiCode_Selected.Visible && TaskAPI.Process != "NPL Master Data Application") || (TaskAPI.Process != "TW NPL Application-DECO" && TaskAPI.Process != "TW NPL Application-PKG" && TaskAPI.Process != "HK NPL Master Application" && TaskAPI.Process != "NPL Master Data Application" && TaskAPI.Process != "P-Plant Extend Application"))
                        {
                            valid.AddRange(TabMaterial2.DataValidation());
                        }
                        #region 添加附件验证
                        if (TaskAPI.Process == "NPL Master Data Application")
                        {
                            if (PMDCAttachment1.IsHaveAttachment == false)
                            {
                                if (PackCode_Selected.Checked)
                                {
                                    valid.AddRange(TabMaterial1.DataValidation());
                                    valid.AddRange(TabMaterial3.DataValidation());
                                }
                                if (SefiCode_Selected.Checked)
                                {
                                    valid.AddRange(TabMaterial2.DataValidation());
                                }
                                //if (SH_Selected.Checked)
                                //{
                                //    valid.AddRange(TabMaterial5.DataValidation());
                                //    valid.AddRange(TabMaterial6.DataValidation());
                                //    valid.AddRange(TabMaterial7.DataValidation());
                                //    valid.AddRange(TabMaterial8.DataValidation());
                                //}
                            }
                        }
                        else
                        {
                            valid.AddRange(TabMaterial3.DataValidation());
                        }
                        #endregion
                        //valid.AddRange(TabMaterial2.DataValidation());
                        //valid.AddRange(TabMaterial3.DataValidation());
                        valid.AddRange(TabMaterial4.DataValidation());
                        valid.AddRange(TabCCC1.DataValidation());
                        valid.AddRange(TabBom1.DataValidation());
                        valid.AddRange(TabBom2.DataValidation());
                        valid.AddRange(TabInsPlan1.DataValidation());
                        valid.AddRange(UserChoose1.DataValidation());
                        valid.AddRange(UsersChoose1.DataValidation());
                        valid.AddRange(TabGroup1.DataValidation());
                        valid.AddRange(TabHierarchy1.DataValidation());

                        valid.AddRange(TabInsQual1.DataValidation());
                        valid.AddRange(TabInsQuan1.DataValidation());
                        valid.AddRange(TWTabInsPlan1.DataValidation());

                        valid.AddRange(TabTJO1.DataValidation());
                        //valid.AddRange(TabPlg1.DataValidation());
                        //valid.AddRange(TabFormul1.DataValidation());
                        valid.AddRange(TabFormu1.DataValidation());
                        valid.AddRange(Detemination1_1.DataValidation());
                        valid.AddRange(Detemination1_2.DataValidation());
                        valid.AddRange(Detemination1_3.DataValidation());
                        valid.AddRange(this.TabHKNpl1.DataValidation());
                    }
                    if (valid.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(valid), valid.Count));
                        return;
                    }

                }
                #endregion
                
                #region
                if (TaskAPI.Process == "NPL Master Data Application")
                {
                    TaskAPI["ISSH"] = SH_Selected.Checked ? "1" : "0";
                    TaskAPI["ISGZ"] = GZ_Selected.Checked ? "1" : "0";
                    TaskAPI["ISLF"] = LF_Selected.Checked ? "1" : "0";
                    TaskAPI["RadionList_NPL"] = RadionList_NPL.SelectedValue;
                    TaskAPI["IsSefiCode"] = SefiCode_Selected.Checked ? "1" : "0";
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {

                    TaskAPI.UserName = UserAPI.UserName;
                    if (TaskAPI.Process == "TJO Base Code Application" || TaskAPI.Process == "MTO Base Code Application")
                    {
                        TaskAPI["CCC_Confirm_Sales_Order"] = UserAPI.UserName;
                    }

                    TaskAPI["Applicator"] = UserAPI.UserName;
                    TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                    TaskAPI["EMAIL_Fill_in_the_Request"] = UserAPI.Mail;
                    TaskAPI["Distribute_S"] = Distribute.SelectedValue;
                    if (TaskAPI.Process != "TW Pack Material Maintenance")
                    {
                        TaskAPI["Actions"] = Actions.SelectedValue;
                    }
                    else
                    {
                        if (Actions.SelectedItem.Text.Contains("Creation") || Actions.SelectedItem.Text.Contains("Extend"))
                        {
                            TaskAPI["Actions"] = "1";
                        }
                    }
                    TaskAPI["NPL_Sefi_BOM"] = NPL_Sefi_BOM.SelectedValue;
                    TaskAPI["Product_Line"] = Product_Line.SelectedValue;
                    TaskAPI["Try_Product"] = Try_Product.SelectedValue;
                    TaskAPI["Channel"] = Channel.SelectedValue;
                    TaskAPI["Affect_APO"] = Affect_APO.SelectedValue;
                    TaskAPI["Change_Modification"] = Change_Modification.SelectedValue;
                    TaskAPI["Time"] = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                    //TaskAPI["ApplicatorEmail"] =UserAPI.Mail;
                    var applicatorEmail = GetEmailByWinId(new List<string> { "'" + UserAPI.UserName + "'" });
                    TaskAPI["ApplicatorEmail"] = applicatorEmail != null && applicatorEmail.Count > 0
                                                     ? applicatorEmail[0]
                                                     : string.Empty;
                    TaskAPI["Notify"] = (Page as PMDC).TabMaterial1.Logistics1.LOG_Volume.Text + (Page as PMDC).TabMaterial1.Marketing1.MKT_Easy_Order_Entry_Code.Text + (Page as PMDC).TabMaterial1.Planning1.PLA_Planning_Material.Text
                                                  + (Page as PMDC).TabMaterial1.Planning1.PLA_Plant_Sp_Matl_Status.SelectedValue + (Page as PMDC).TabMaterial1.Planning1.PLA_Strategy_Group.SelectedValue;
                    TaskAPI["SAPCode"] = (Page as PMDC).TabMaterial1.SAPCode1.SAP_SAP_Code.Text;
                    TaskAPI["Code_Selected"] = Code_Selected.Checked ? "1" : "0";
                    TaskAPI["BOM_Selected"] = BOM_Selected.Checked ? "1" : "0";
                    TaskAPI["IsSefiBom"] = Sefi_Bom.Checked ? "1" : "0";
                    TaskAPI["IsINP"] = INP.Checked ? "1" : "0";
                    TaskAPI["ProductionLine"] = TabCCC1.ProductionLine;
                    TaskAPI["Color"] = TabCCC1.Color;
                    TaskAPI["TJO_ProductionLine"] = TabTJO1.TJO_ProductionLine;
                    TaskAPI["TJO_Color"] = TabTJO1.TJO_Color;
                    TaskAPI["IsPackCode"] = PackCode_Selected.Checked ? "1" : "0";
                    TaskAPI["IsSefiCode"] = SefiCode_Selected.Checked ? "1" : "0";
                    TaskAPI["IsIpCode"] = this.IP_Selected.Checked ? "1" : "0";
                    TaskAPI["IsQuanCode"] = this.Quan_Selected.Checked ? "1" : "0";
                    TaskAPI["IsQualCode"] = this.Qual_Selected.Checked ? "1" : "0";
                    TaskAPI["Alternative_Bom"] = (Page as PMDC).TabBom1.T_Alternative_Bom.Text;
                    TaskAPI["Raw_Code"] = rd_Raw_Code.SelectedIndex.ToString();
                    TaskAPI["Business_Priority"] = DrpPriority.SelectedItem.ToString();
                    

                    //TaskAPI["R_Technical"] = "apac.ad.ici.com/lud11";
                    //TaskAPI["R_Sample_is_received"] = "apac.ad.ici.com/lud11";
                    //TaskAPI["R_DMO_Maintain"] = "apac.ad.ici.com/shie11";
                    //TaskAPI["R_DMO_Check"] = "apac.ad.ici.com/shie11";
                    //Tang Bin

                    if (TaskAPI.IsInitiate)
                    {

                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");

                        #region                         
                        
                        if (TaskAPI.Process == "MTO Base Code Application")
                        {
                            ApplicatorNo.Text = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                            TaskAPI["Department"] = Department;
                            TaskAPI["ApplicationNo"] = ApplicatorNo.Text;
                            TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                            TaskAPI["ProductionLine"] = TabCCC1.ProductionLine;
                            TaskAPI["Color"] = TabCCC1.Color;
                            TaskAPI["Inform_Applicator_Order"] = UserAPI.Mail;
                            TaskAPI["Inform_Applicator"] = UserAPI.Mail;

                        }
                        else
                        {
                            ApplicatorNo.Text = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                            
                            TaskAPI["Department"] = Department;
                            
                            TaskAPI["ApplicationNo"] = ApplicatorNo.Text;
                            
                            TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;

                        }
                        #endregion

                        #region 从数据库取得流程步骤处理人
                        if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit
                                                && Distribute_B.Text != Distribute.SelectedValue && !Assessment1.isReturned && TaskAPI.Process != "P-Plant Extend Application")
                        {

                            SortedList<string, string> tar = new SortedList<string, string>();
                            IList<mdc_Recipient> srcs = (mdc_Recipient.process == TaskAPI.Process
                                                      & (mdc_Recipient.distribute == Distribute.SelectedValue | mdc_Recipient.distribute == "*")
                                                      & mdc_Recipient.status == 1).List<mdc_Recipient>();
                            foreach (mdc_Recipient src in srcs)
                            {
                                if (!tar.ContainsKey(src.Step))
                                {
                                    tar.Add(src.Step, src.Recipient);
                                    continue;
                                }

                                if (tar.Values[tar.IndexOfKey(src.Step)].Contains(src.Recipient))
                                {
                                    continue;
                                }

                                tar[src.Step] = tar.Values[tar.IndexOfKey(src.Step)] + "," + src.Recipient;
                            }


                            //步骤处理人赋值
                            for (int i = 0; i < tar.Keys.Count; i++)
                            {
                                TaskAPI["R_" + tar.Keys[i].Replace(" ", "_")] = tar.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                            }
                            if (TaskAPI.Process == "NPL Master Data Application")
                            {
                                m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == TaskAPI["Technical"])).ListFirst<m_OrgChart>();
                                if (oc != null)
                                {
                                    TaskAPI["R_Technical_Manager"] = oc.WinID;
                                }
                            }
                            else if (TaskAPI.Process == "Product Grouphiera Application")
                            {
                                m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                                if (oc != null)
                                {
                                    TaskAPI["R_Marketing_Manager"] = oc.WinID;
                                }

                                m_OrgChart oc1 = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == TaskAPI["Technical"])).ListFirst<m_OrgChart>();
                                if (oc1 != null)
                                {
                                    TaskAPI["R_Technical_Manager"] = oc1.WinID;
                                }
                            }



                            else
                            {
                                m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                                if (oc != null)
                                {
                                    TaskAPI["R_Marketing_Manager"] = oc.WinID;
                                    TaskAPI["R_Technical_Manager"] = oc.WinID;
                                    TaskAPI["R_Trade_Marketing_Manager"] = oc.WinID;
                                    TaskAPI["R_Trade_Manager_Approve"] = oc.WinID;
                                    TaskAPI["R_Line_Manager"] = oc.WinID;
                                    TaskAPI["R_Line_Manager_Approve"] = oc.WinID;
                                    TaskAPI["R_Manager_Approve"] = oc.WinID;
                                }
                            }

                        }

                        else if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit
                                            && Distribute_B.Text != Distribute.SelectedValue && !Assessment1.isReturned && TaskAPI.Process == "P-Plant Extend Application")
                        {


                            SortedList<string, string> tar = new SortedList<string, string>();
                            IList<m_Production> srcs = (m_Production.process == TaskAPI.Process
                                                      & (m_Production.distribute == Distribute.SelectedValue | m_Production.distribute == "*")
                                                      & m_Production.status == 1).List<m_Production>();
                            foreach (m_Production src in srcs)
                            {
                                if (!tar.ContainsKey(src.Step))
                                {
                                    tar.Add(src.Step, src.Recipient);
                                    continue;
                                }

                                if (tar.Values[tar.IndexOfKey(src.Step)].Contains(src.Recipient))
                                {
                                    continue;
                                }

                                tar[src.Step] = tar.Values[tar.IndexOfKey(src.Step)] + "," + src.Recipient;
                            }

                            //步骤处理人赋值
                            for (int i = 0; i < tar.Keys.Count; i++)
                            {
                                TaskAPI["R_" + tar.Keys[i].Replace(" ", "_")] = tar.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                            }
                            if (TaskAPI.Process == "NPL Master Data Application")
                            {
                                m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == TaskAPI["Technical"])).ListFirst<m_OrgChart>();
                                if (oc != null)
                                {
                                    TaskAPI["R_Technical_Manager"] = oc.WinID;
                                }
                            }
                            //加hirachy
                            else
                            {
                                m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                                if (oc != null)
                                {
                                    TaskAPI["R_Marketing_Manager"] = oc.WinID;
                                    TaskAPI["R_Technical_Manager"] = oc.WinID;
                                    TaskAPI["R_Trade_Marketing_Manager"] = oc.WinID;
                                    TaskAPI["R_Trade_Manager_Approve"] = oc.WinID;
                                    TaskAPI["R_Line_Manager"] = oc.WinID;
                                    TaskAPI["R_Line_Manager_Approve"] = oc.WinID;
                                    TaskAPI["R_Manager_Approve"] = oc.WinID;
                                }
                            }

                        }
                        
                        #endregion
                    }
                    
                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text) + " / " + ApplicatorNo.Text;

                }
                else
                {

                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion2 == "" ? "1" : Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"] = TaskAPI.TaskID;
                    Assessment1.SetStepUserName(TaskAPI.Step, TaskAPI.UserName);

                }

                #endregion


                #region  给引擎处理人赋值
                if (Convert.ToInt32(Incident) > 0)
                {
                    mdc_MDC recipient = (mdc_MDC.incident == Incident & mdc_MDC.process == Process).ListFirst<mdc_MDC>();
                    TaskDB.Log("", false, "处理人:" + recipient.User_Finance);
                    //if (!string.IsNullOrEmpty(recipient.User_PV) | !string.IsNullOrEmpty(recipient.User_PV1) | !string.IsNullOrEmpty(recipient.User_PV2) | !string.IsNullOrEmpty(recipient.User_PV3))
                    //if (!string.IsNullOrEmpty(recipient.User_PV1) | !string.IsNullOrEmpty(recipient.User_PV2) | !string.IsNullOrEmpty(recipient.User_PV3))
                    //{
                    TaskDB.Log("", false, "处理人1_1:" + recipient.User_PV);
                    if (!string.IsNullOrEmpty(recipient.User_PV)) TaskAPI["Production_PV"] = recipient.User_PV;
                    TaskDB.Log("", false, "处理人1:" + recipient.User_PV1);
                    if (!string.IsNullOrEmpty(recipient.User_PV1)) TaskAPI["Production_PV2"] = recipient.User_PV1;
                    TaskDB.Log("", false, "处理人2:" + recipient.User_PV2);
                    if (!string.IsNullOrEmpty(recipient.User_PV2)) TaskAPI["Production_PV3"] = recipient.User_PV2;
                    TaskDB.Log("", false, "处理人3:" + recipient.User_PV3);
                    if (!string.IsNullOrEmpty(recipient.User_PV3)) TaskAPI["Production_PV4"] = recipient.User_PV3;
                    if (!string.IsNullOrEmpty(recipient.User_Finance)) TaskAPI["Finance_Run_Cost"] = recipient.User_Finance;
                    if (!string.IsNullOrEmpty(recipient.User_Finance1)) TaskAPI["Finance_Run_Cost2"] = recipient.User_Finance1;
                    if (!string.IsNullOrEmpty(recipient.User_Finance2)) TaskAPI["Finance_Run_Cost3"] = recipient.User_Finance2;
                    if (!string.IsNullOrEmpty(recipient.User_Finance3)) TaskAPI["Finance_Run_Cost4"] = recipient.User_Finance3;
                    if (!string.IsNullOrEmpty(recipient.Run_ICD_Price)) TaskAPI["Run_ICD_Price"] = recipient.Run_ICD_Price;
                    if (!string.IsNullOrEmpty(recipient.Run_ICD_Price2)) TaskAPI["Run_ICD_Price2"] = recipient.Run_ICD_Price2;
                    //}
                    if (!string.IsNullOrEmpty(recipient.User_Marketing_Add_Data) | !string.IsNullOrEmpty(recipient.User_Purchasing_Add_Data) | !string.IsNullOrEmpty(recipient.User_Logistic_Add_Data) | !string.IsNullOrEmpty(recipient.User_Planning))
                    {
                        TaskAPI["Marketing_Add_Data"] = recipient.User_Marketing_Add_Data;
                        TaskAPI["Purchasing_Add_Data"] = recipient.User_Purchasing_Add_Data;
                        TaskAPI["Logistic_Add_Data"] = recipient.User_Logistic_Add_Data;
                        TaskAPI["Planning"] = recipient.User_Planning;
                    }
                }
                #endregion

                
                #region 步骤提交
                Storage.TransactionExecute(Storage.Context1, o =>
                {

                    #region “Fill in the request”步骤
                    if (TaskAPI.IsBeginStep || (TaskAPI.Process == "NPL Master Data Application" && TaskAPI.Step == "Production Site Select"))
                    {
                        mdc_MDC mdc;
                        if ((mdc_MDC.process == TaskAPI.Process & mdc_MDC.incident == TaskAPI.Incident & mdc_MDC.userName == UserAPI.UserName).Count<mdc_MDC>() > 0)
                        {
                            mdc = (mdc_MDC.process == TaskAPI.Process & mdc_MDC.incident == TaskAPI.Incident & mdc_MDC.userName == UserAPI.UserName).ListFirst<mdc_MDC>();
                        }
                        else
                        {
                            mdc = new mdc_MDC();
                            mdc.ApplicationNo = ApplicatorNo.Text;
                            mdc.Process = TaskAPI.Process;
                            mdc.Incident = TaskAPI.Incident;
                            mdc.UserFullName = UserAPI.UserFullName;
                            mdc.UserName = UserAPI.UserName;
                            mdc.Time = System.DateTime.Now;
                            mdc.Department = Department;
                            mdc.ProductionLine = TabCCC1.ProductionLine;
                            mdc.Color = TabCCC1.Color;
                            mdc.TJO_ProductionLine = TabTJO1.TJO_ProductionLine;
                            mdc.TJO_Color = TabTJO1.TJO_Color;
                            mdc.Production = Production.SelectedValue;


                            //mdc.NPL_Sefi_BOM = NPL_Sefi_BOM.SelectedValue;
                            //mdc.Code_Selected = Code_Selected.Checked ? "1" : "0";
                            //mdc.BOM_Selected = BOM_Selected.Checked ? "1" : "0";

                            //mdc.HK_ADVE_Code_Selected = HK_ADVE_Code_Selected.Checked ? "1" : "0";
                            //mdc.HK_ADVE_Code_Dummy_Selected = HK_ADVE_Code_Dummy_Selected.Checked ? "1" : "0";

                            //mdc.Sefi_Bom = Sefi_Bom.Checked ? "1" : "0";
                            //mdc.INP = INP.Checked ? "1" : "0";
                            mdc.IsShowSAPCode = ((TabMaterial1.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial2.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial3.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial4.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial5.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial6.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial7.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code))
                                              || (TabMaterial8.Visible && !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code)) ? "C" : "");
                            mdc.IsShowSAPCode = !string.IsNullOrEmpty(TabMaterial1.Status.SAP_Code) ? "C" : "";
                        }

                        mdc.NPL_Sefi_BOM = NPL_Sefi_BOM.SelectedValue;
                        mdc.Product_Line = Product_Line.SelectedValue;
                        mdc.Try_Product = Try_Product.SelectedValue;
                        mdc.Channel = Channel.SelectedValue;
                        mdc.Change_KPL = Change_KPL.SelectedValue;
                        mdc.Affect_APO = Affect_APO.SelectedValue;


                        mdc.Change_Modification = Change_Modification.SelectedValue;
                        mdc.Code_Selected = Code_Selected.Checked ? "1" : "0";
                        mdc.BOM_Selected = BOM_Selected.Checked ? "1" : "0";
                        mdc.IsPackcode = PackCode_Selected.Checked ? "1" : "0";
                        mdc.IsSefiCode = SefiCode_Selected.Checked ? "1" : "0";
                        mdc.IsIPCode = this.IP_Selected.Checked ? "1" : "0";
                        mdc.IsQualCode = this.Qual_Selected.Checked ? "1" : "0";
                        mdc.IsQuanCode = this.Quan_Selected.Checked ? "1" : "0";
                        mdc.DrpPriority = this.DrpPriority.SelectedItem.ToString();
                        (Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial2.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial3.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial4.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial5.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial6.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial7.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;
                        (Page as PMDC).TabMaterial8.DMO1.DMO_DrpPriority.SelectedValue = this.DrpPriority.SelectedValue;

                        if (TaskAPI.Process == "NPL Master Data Application")
                        {
                            mdc.IsSH_Selected = SH_Selected.Checked ? "1" : "0";
                            mdc.IsGZ_Selected = GZ_Selected.Checked ? "1" : "0";
                            mdc.IsLF_Selected = LF_Selected.Checked ? "1" : "0";
                            mdc.IsRadionList_NPL = RadionList_NPL.SelectedValue;
                            TaskAPI["ISSH"] = SH_Selected.Checked ? "1" : "0";
                            TaskAPI["ISGZ"] = GZ_Selected.Checked ? "1" : "0";
                            TaskAPI["ISLF"] = LF_Selected.Checked ? "1" : "0";
                            TaskAPI["RadionList_NPL"] = RadionList_NPL.SelectedValue;
                        }
                        if (TaskAPI.Process == "HK ADVE Code Application")
                        {
                            mdc.rd_HK_ADVE_Biz_Type = rd_HK_ADVE_Biz_Type.SelectedIndex.ToString();
                        }
                        if (TaskAPI.Process == "TW Raw Code Application")
                        {
                            mdc.rd_Raw_Code = rd_Raw_Code.SelectedIndex.ToString();
                        }


                        mdc.Sefi_Bom = Sefi_Bom.Checked ? "1" : "0";
                        mdc.INP = INP.Checked ? "1" : "0";

                        mdc.Actions = Actions.SelectedValue;
                        mdc.ActionsName = Actions.SelectedItem.Text;

                        mdc.DrpPriority = DrpPriority.SelectedValue;
                        mdc.Production = Production.SelectedValue;
                        mdc.Distribute = Distribute.SelectedValue;
                        mdc.Status = 0;
                        mdc.User_PV = mdc.User_PV1 = mdc.User_PV2 = mdc.User_PV3 = mdc.User_Finance = mdc.User_Finance1 = mdc.User_Finance2 = mdc.User_Finance3 = mdc.Run_ICD_Price = mdc.Run_ICD_Price2 = string.Empty;
                        if (TaskAPI.Process == "PKG Fini Code BOM Application" || TaskAPI.Process == "PKG Sefi Code BOM Application")
                        {
                            mdc.User_PV = PKG_PV;
                            mdc.User_Finance = PKG_Cost;
                        }
                        Storage.Save(mdc);
                        if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                        //if (TaskAPI.IsBeginStep)
                        {
                            mdc_Priority pro;
                            if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                            {
                                pro = new mdc_Priority();
                                pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                                pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                                //mdc_Material.dMO_Priority = DrpPriority.SelectedItem.Text;
                                Storage.Save(pro);
                            }
                            else
                            {
                                pro = new mdc_Priority();
                                pro.Process = TaskAPI.Process;
                                pro.Incident = TaskAPI.Incident;
                                pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                                Storage.Save(pro);
                            }
                            //mdc_Material drp;
                            //if ((mdc_Material.process == TaskAPI.Process & mdc_Material.incident == TaskAPI.Incident).Count<mdc_Material>() > 0)
                            //{
                            //    drp = new mdc_Material();
                            //    drp = (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == TaskAPI.Incident).ListFirst<mdc_Material>();
                            //    drp.DMO_Priority = DrpPriority.SelectedValue;
                            //    Storage.Save(drp);
                            //}
                            //else
                            //{
                            //    pro = new mdc_Priority();
                            //    pro.Process = TaskAPI.Process;
                            //    pro.Incident = TaskAPI.Incident;
                            //    pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            //    Storage.Save(pro);
                            //}
                        }

                    }
                    #endregion


                    #region “Tabs” 写入
                    TabMaterial1.Save();
                    TabMaterial2.Save();
                    TabMaterial3.Save();
                    TabMaterial4.Save();
                    TabMaterial5.Save();
                    TabMaterial6.Save();
                    TabMaterial7.Save();
                    TabMaterial8.Save();
                    TabBom1.Save();
                    TabBom2.Save();
                    TabBom3.Save();
                    TabInsPlan1.Save();
                    TabBarcode1.Save();
                    TabCCC1.Save();
                    UsersChoose1.SaveStatus(Assessment1.Assessment.Opinion == "1" ? "1" : "0");
                    TabGroup1.Save();
                    TabHierarchy1.Save();
                    TabInsQual1.Save();
                    TabInsQuan1.Save();
                    TabTJO1.Save();
                    TabPlg1.Save();
                    TabScan1.Save();
                    TabFormu1.Save();
                    TabFormul1.Save();
                    Detemination1_1.Save();
                    Detemination1_2.Save();
                    Detemination1_3.Save();
                    this.TabHKNpl1.Save();
                    this.TWTabInsPlan1.Save();
                    #endregion


                });

                #region DMO步骤
                if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO BOM Approve" || TaskAPI.Step == "DMO BOM Maintain") && !string.IsNullOrEmpty((Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                {
                    mdc_Priority pro;
                    if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                    {
                        pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();

                        pro.DMO_Priority = Convert.ToInt32((Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue);

                        Storage.Save(pro);

                        TaskAPI["DMO_Priority"] = (Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedItem.ToString();


                    }
                    else
                    {
                        pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        try
                        {
                            TaskDB.LogInfo(string.Format("A is {0}", string.IsNullOrEmpty((Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue)));
                            

                            if (TabMaterial1.DMO1.DMO_DrpPriority !=null)
                            {
                                //pro.DMO_Priority = Convert.ToInt32((Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue);
                                pro.DMO_Priority = 1;
                                TaskDB.LogInfo(string.Format("B is {0}", Convert.ToInt32((Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue)));
                                TaskAPI["DMO_Priority"] = (Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedItem.ToString();
                                TaskDB.LogInfo(string.Format("D is {0}", (Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedItem.ToString()));
                            }
                            else
                            {
                                TaskAPI["DMO_Priority"] = string.Empty;
                                TaskDB.LogInfo("D is Empty");
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDB.LogInfo(string.Format("Exception:{0}", ex.Message.ToString()));
                        }                     

                        Storage.Save(pro);
                    }

                }
                #endregion


                #region 退回步骤并返回功能 传值

                if (TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] != null)
                {
                    object[] obj = (object[])(TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")]);
                    for (int i = 0; i < obj.GetUpperBound(0); i++)
                    {
                        obj[i] = null;
                    }
                    obj[0] = UserAPI.UserName;
                    TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_")] = obj;
                }
                //多节点退回
                if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                {
                    Assessment1.SetAsReturn(true);
                    TaskAPI.DirectActive(Assessment1.JumpStep);
                }
                else
                {
                    Assessment1.SetAsReturn(false);
                }
                Assessment1.SubmitTo();
                bool flg = TaskAPI.Send();

                //Storage.Save(Assessment1.Assessment);
                #endregion



                #region 如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    (mdc_MDC.process == TaskAPI.Process & mdc_MDC.incident == 0 & mdc_MDC.userName == UserAPI.UserName).Edit<mdc_MDC>(p => { p.Incident = TaskAPI.Incident; });
                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p => { p.Incident = TaskAPI.Incident; });
                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p => { p.Incident = TaskAPI.Incident; });

                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial1.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial2.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial3.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial4.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial5.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial6.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial7.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabMaterial8.Status.IsEdited)
                    {
                        (mdc_Material.process == TaskAPI.Process & mdc_Material.incident == 0 & mdc_Material.userName == UserAPI.UserName).Edit<mdc_Material>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabBom1.Status.IsEdited)
                    {

                        switch (TabBom1.Status.Category)
                        {
                            case "SEFI":
                                (mdc_Bom_Sefi_1.process == TaskAPI.Process & mdc_Bom_Sefi_1.incident == 0 & mdc_Bom_Sefi_1.userName == UserAPI.UserName).Edit<mdc_Bom_Sefi_1>(p => { p.Incident = TaskAPI.Incident; });
                                (mdc_Bom_Sefi_2.process == TaskAPI.Process & mdc_Bom_Sefi_2.incident == 0 & mdc_Bom_Sefi_2.userName == UserAPI.UserName).Edit<mdc_Bom_Sefi_2>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "MTO-SEFI":
                                (mdc_Bom_MTO_Sefi_1.process == TaskAPI.Process & mdc_Bom_MTO_Sefi_1.incident == 0 & mdc_Bom_MTO_Sefi_1.userName == UserAPI.UserName).Edit<mdc_Bom_MTO_Sefi_1>(p => { p.Incident = TaskAPI.Incident; });
                                (mdc_Bom_MTO_Sefi_2.process == TaskAPI.Process & mdc_Bom_MTO_Sefi_2.incident == 0 & mdc_Bom_MTO_Sefi_2.userName == UserAPI.UserName).Edit<mdc_Bom_MTO_Sefi_2>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "MTO-FINI":
                                (mdc_Bom_MTO_Fini.process == TaskAPI.Process & mdc_Bom_MTO_Fini.incident == 0 & mdc_Bom_MTO_Fini.userName == UserAPI.UserName).Edit<mdc_Bom_MTO_Fini>(p => { p.Incident = TaskAPI.Incident; });
                                break;

                            case "FINI":
                                (mdc_Bom_Fini_1.process == TaskAPI.Process & mdc_Bom_Fini_1.incident == 0 & mdc_Bom_Fini_1.userName == UserAPI.UserName).Edit<mdc_Bom_Fini_1>(p => { p.Incident = TaskAPI.Incident; });
                                (mdc_Bom_Fini_2.process == TaskAPI.Process & mdc_Bom_Fini_2.incident == 0 & mdc_Bom_Fini_2.userName == UserAPI.UserName).Edit<mdc_Bom_Fini_2>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "NPL-FINI-1":
                                (mdc_Bom_NPL_Fini_1.process == TaskAPI.Process & mdc_Bom_NPL_Fini_1.incident == 0 & mdc_Bom_NPL_Fini_1.userName == UserAPI.UserName).Edit<mdc_Bom_NPL_Fini_1>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "NPL-FINI-2":
                                (mdc_Bom_NPL_Fini_2.process == TaskAPI.Process & mdc_Bom_NPL_Fini_2.incident == 0 & mdc_Bom_NPL_Fini_2.userName == UserAPI.UserName).Edit<mdc_Bom_NPL_Fini_2>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "PKG-FINI":
                                (mdc_Bom_PKG_Fini.process == TaskAPI.Process & mdc_Bom_PKG_Fini.incident == 0 & mdc_Bom_PKG_Fini.userName == UserAPI.UserName).Edit<mdc_Bom_PKG_Fini>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "PLALOG":
                                (mdc_Material_Plalog.process == TaskAPI.Process & mdc_Material_Plalog.incident == 0 & mdc_Material_Plalog.userName == UserAPI.UserName).Edit<mdc_Material_Plalog>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "SCAN":
                                (mdc_Material_Scan.process == TaskAPI.Process & mdc_Material_Scan.incident == 0 & mdc_Material_Scan.userName == UserAPI.UserName).Edit<mdc_Material_Scan>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "FORMU":
                                (mdc_Material_Formu.process == TaskAPI.Process & mdc_Material_Formu.incident == 0 & mdc_Material_Formu.userName == UserAPI.UserName).Edit<mdc_Material_Formu>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                            case "FORMUL":
                                (mdc_Material_Formul.process == TaskAPI.Process & mdc_Material_Formul.incident == 0 & mdc_Material_Formul.userName == UserAPI.UserName).Edit<mdc_Material_Formul>(p => { p.Incident = TaskAPI.Incident; });
                                break;
                        }
                    }
                    if (Detemination1_1.Status.IsEdited)
                    {
                        (mdc_spm_Determination_1.process == TaskAPI.Process & mdc_spm_Determination_1.incident == 0 & mdc_spm_Determination_1.userName == UserAPI.UserName).Edit<mdc_spm_Determination_1>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (Detemination1_2.Status.IsEdited)
                    {
                        (mdc_spm_Determination_2.process == TaskAPI.Process & mdc_spm_Determination_2.incident == 0 & mdc_spm_Determination_2.userName == UserAPI.UserName).Edit<mdc_spm_Determination_2>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (Detemination1_3.Status.IsEdited)
                    {
                        (mdc_spm_Determination_3.process == TaskAPI.Process & mdc_spm_Determination_3.incident == 0 & mdc_spm_Determination_3.userName == UserAPI.UserName).Edit<mdc_spm_Determination_3>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabHKNpl1.Status.IsEdited)
                    {
                        (mdc_HK_NPL_Customer_Application.process == TaskAPI.Process & mdc_HK_NPL_Customer_Application.incident == 0 & mdc_HK_NPL_Customer_Application.userName == UserAPI.UserName).Edit<mdc_HK_NPL_Customer_Application>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TWTabInsPlan1.Status.IsEdited)
                    {
                        (TW_mdc_Insplan.process == TaskAPI.Process & TW_mdc_Insplan.incident == 0 & TW_mdc_Insplan.userName == UserAPI.UserName).Edit<TW_mdc_Insplan>(p => { p.Incident = TaskAPI.Incident; });
                    }
                    if (TabInsPlan1.Status.IsEdited)
                    {
                        (mdc_Ins_Plan_1.process == TaskAPI.Process & mdc_Ins_Plan_1.incident == 0 & mdc_Ins_Plan_1.userName == UserAPI.UserName).Edit<mdc_Ins_Plan_1>(p => { p.Incident = TaskAPI.Incident; });
                        (mdc_Ins_Plan_2.process == TaskAPI.Process & mdc_Ins_Plan_2.incident == 0 & mdc_Ins_Plan_2.userName == UserAPI.UserName).Edit<mdc_Ins_Plan_2>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabBarcode1.Status.IsEdited)
                    {
                        (mdc_Barcode.process == TaskAPI.Process & mdc_Barcode.incident == 0 & mdc_Barcode.userName == UserAPI.UserName).Edit<mdc_Barcode>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabCCC1.Status.IsEdited)
                    {
                        (mdc_CCC.process == TaskAPI.Process & mdc_CCC.incident == 0 & mdc_CCC.userName == UserAPI.UserName).Edit<mdc_CCC>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabGroup1.Status.IsEdited)
                    {
                        (mdc_Product_Group.process == TaskAPI.Process & mdc_Product_Group.incident == 0 & mdc_Product_Group.userName == UserAPI.UserName).Edit<mdc_Product_Group>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabHierarchy1.Status.IsEdited)
                    {
                        (mdc_Product_Hierarchy.process == TaskAPI.Process & mdc_Product_Hierarchy.incident == 0 & mdc_Product_Hierarchy.userName == UserAPI.UserName).Edit<mdc_Product_Hierarchy>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabInsQual1.Status.IsEdited)
                    {
                        (mdc_Ins_Qual.process == TaskAPI.Process & mdc_Ins_Qual.incident == 0 & mdc_Ins_Qual.userName == UserAPI.UserName).Edit<mdc_Ins_Qual>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabInsQuan1.Status.IsEdited)
                    {
                        (mdc_Ins_Quan.process == TaskAPI.Process & mdc_Ins_Quan.incident == 0 & mdc_Ins_Quan.userName == UserAPI.UserName).Edit<mdc_Ins_Quan>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabTJO1.Status.IsEdited)
                    {
                        (mdc_TJO.process == TaskAPI.Process & mdc_TJO.incident == 0 & mdc_TJO.userName == UserAPI.UserName).Edit<mdc_TJO>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabPlg1.Status.IsEdited)
                    {
                        (mdc_Material_Plalog.process == TaskAPI.Process & mdc_Material_Plalog.incident == 0 & mdc_Material_Plalog.userName == UserAPI.UserName).Edit<mdc_Material_Plalog>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabScan1.Status.IsEdited)
                    {
                        (mdc_Material_Scan.process == TaskAPI.Process & mdc_Material_Scan.incident == 0 & mdc_Material_Scan.userName == UserAPI.UserName).Edit<mdc_Material_Scan>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabFormu1.Status.IsEdited)
                    {
                        (mdc_Material_Formu.process == TaskAPI.Process & mdc_Material_Formu.incident == 0 & mdc_Material_Formu.userName == UserAPI.UserName).Edit<mdc_Material_Formu>(p => { p.Incident = TaskAPI.Incident; });
                    }

                    if (TabFormul1.Status.IsEdited)
                    {
                        (mdc_Material_Formul.process == TaskAPI.Process & mdc_Material_Formul.incident == 0 & mdc_Material_Formul.userName == UserAPI.UserName).Edit<mdc_Material_Formul>(p => { p.Incident = TaskAPI.Incident; });
                    }
                }
                #endregion


                string AssessmentID = "";
                if (flg)
                {
                    t_Assessment assTmp = new t_Assessment();
                    assTmp.AssignedToUserFullName = Assessment1.Assessment.AssignedToUserFullName;
                    assTmp.AssignedToUserName = Assessment1.Assessment.AssignedToUserName;
                    assTmp.Department = Assessment1.Assessment.Department;
                    assTmp.Incident = Convert.ToInt32(TaskAPI.Incident);
                    assTmp.Opinion = Assessment1.Assessment.Opinion;
                    assTmp.Opinion2 = Assessment1.Assessment.Opinion2;
                    assTmp.OpinionText = Assessment1.Assessment.OpinionText;
                    assTmp.OpinionText2 = Assessment1.Assessment.OpinionText2;
                    assTmp.Process = TaskAPI.Process;
                    assTmp.Remark = Assessment1.Assessment.Remark;
                    assTmp.ReturnTo = Assessment1.Assessment.ReturnTo;
                    assTmp.Signature = Assessment1.Assessment.Signature;
                    assTmp.StartTime = Assessment1.Assessment.StartTime;
                    assTmp.Status = Assessment1.Assessment.Status;
                    assTmp.Time = DateTime.Now;
                    assTmp.Step = Assessment1.Assessment.Step;
                    assTmp.UserFullName = Assessment1.Assessment.UserFullName;
                    assTmp.UserName = Assessment1.Assessment.UserName;
                    Storage.Save(assTmp);
                    AssessmentID = assTmp.ID;
                }


                IList<mdc_MDC> mdctmp = (mdc_MDC.process == TaskAPI.Process & mdc_MDC.incident == TaskAPI.Incident).List<mdc_MDC>();
                for (int i = 0; i < mdctmp.Count; i++)
                    Storage.Context1.ExecuteNonQuery(new Command("sp_SaveStepStatus 'mdc_MDC', '" + AssessmentID + "', '" + mdctmp[i].ID.ToString() + "'"));

                #endregion


                Send.Visible = false;
                ClearStoreAPI();
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用PMDC方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }

        #region 方法 InitTabTags
        protected void InitTabTags()
        {


            SetVisible(false, PP25, PP26, PP27, PP28, PP29, PP20, PP24, PP23, PP21, PP22, PP1, PP2, PP3, PP18, PP4, PP5, PP6, PP7, PP8, PP9, PP10, PP11, PP12, PP13, PP14, PP15, PP16, PP17);
            MM1.CssClass = "tabs1";
            MM2.CssClass = "tabs1";
            MM3.CssClass = "tabs1";
            MM4.CssClass = "tabs1";
            BOM1.CssClass = "tabs1";
            BOM2.CssClass = "tabs1";
            INP1.CssClass = "tabs1";
            BAR1.CssClass = "tabs1";
            CCC1.CssClass = "tabs1";
            TJO1.CssClass = "tabs1";
            PR1.CssClass = "tabs1";
            PR2.CssClass = "tabs1";
            QUAL.CssClass = "tabs1";
            QUAN.CssClass = "tabs1";
            PLALOG1.CssClass = "tabs1";
            SCAN1.CssClass = "tabs1";
            FORMU1.CssClass = "tabs1";
            FORMU2.CssClass = "tabs1";
            DD1.CssClass = "tabs1";
            DD2.CssClass = "tabs1";
            DD3.CssClass = "tabs1";
            HKNPL.CssClass = "tabs1";
            TWIP.CssClass = "tabs1";
            //TB添加
            SHMM1.CssClass = "tabs1";
            SHMM2.CssClass = "tabs1";
            SHMM3.CssClass = "tabs1";
            SHMM4.CssClass = "tabs1";
            BOM3.CssClass = "tabs1";

            MM1.Visible = TabMaterial1.Status.IsUsed;
            MM2.Visible = TabMaterial2.Status.IsUsed;
            MM3.Visible = TabMaterial3.Status.IsUsed;
            MM4.Visible = TabMaterial4.Status.IsUsed;
            BOM1.Visible = TabBom1.Status.IsUsed;
            BOM2.Visible = TabBom2.Status.IsUsed;
            INP1.Visible = TabInsPlan1.Status.IsUsed;
            BAR1.Visible = TabBarcode1.Status.IsUsed;
            CCC1.Visible = TabCCC1.Status.IsUsed;
            PR1.Visible = TabGroup1.Status.IsUsed;
            PR2.Visible = TabHierarchy1.Status.IsUsed;
            QUAL.Visible = TabInsQual1.Status.IsUsed;
            QUAN.Visible = TabInsQuan1.Status.IsUsed;
            TJO1.Visible = TabTJO1.Status.IsUsed;
            PLALOG1.Visible = TabPlg1.Status.IsUsed;
            SCAN1.Visible = TabScan1.Status.IsUsed;
            FORMU1.Visible = TabFormu1.Status.IsUsed;
            FORMU2.Visible = TabFormul1.Status.IsUsed;
            DD1.Visible = Detemination1_1.Status.IsUsed;
            DD2.Visible = Detemination1_2.Status.IsUsed;
            DD3.Visible = Detemination1_3.Status.IsUsed;
            HKNPL.Visible = TabHKNpl1.Status.IsUsed;
            TWIP.Visible = TWTabInsPlan1.Status.IsUsed;
            //TB添加
            if (TaskAPI.Process == "NPL Master Data Application")
            {
                if (SH_Selected.Checked)
                {
                    SHMM1.Visible = TabMaterial5.Status.IsUsed;
                    SHMM2.Visible = TabMaterial6.Status.IsUsed;
                    SHMM3.Visible = TabMaterial7.Status.IsUsed;
                    SHMM4.Visible = TabMaterial8.Status.IsUsed;
                }
                else
                {
                    SHMM1.Visible = false;
                    SHMM2.Visible = false;
                    SHMM3.Visible = false;
                    SHMM4.Visible = false;
                }
            }
            else
            {
                SHMM1.Visible = TabMaterial5.Status.IsUsed;
                SHMM2.Visible = TabMaterial6.Status.IsUsed;
                SHMM3.Visible = TabMaterial7.Status.IsUsed;
                SHMM4.Visible = TabMaterial8.Status.IsUsed;
            }
            BOM3.Visible = TabBom3.Status.IsUsed;
            DD1.Text = Detemination1_1.Status.Name;
            DD2.Text = Detemination1_2.Status.Name;
            DD3.Text = Detemination1_3.Status.Name;
            HKNPL.Text = TabHKNpl1.Status.Name;
            TWIP.Text = TWTabInsPlan1.Status.Name;

            MM1.Text = TabMaterial1.Status.Name;
            MM2.Text = TabMaterial2.Status.Name;
            MM3.Text = TabMaterial3.Status.Name;
            MM4.Text = TabMaterial4.Status.Name;
            BOM1.Text = TabBom1.Status.Name;
            BOM2.Text = TabBom2.Status.Name;
            INP1.Text = TabInsPlan1.Status.Name;
            BAR1.Text = TabBarcode1.Status.Name;
            CCC1.Text = TabCCC1.Status.Name;
            PR1.Text = TabGroup1.Status.Name;
            PR2.Text = TabHierarchy1.Status.Name;
            QUAL.Text = TabInsQual1.Status.Name;
            QUAN.Text = TabInsQuan1.Status.Name;
            TJO1.Text = TabTJO1.Status.Name;
            PLALOG1.Text = TabPlg1.Status.Name;
            SCAN1.Text = TabScan1.Status.Name;
            FORMU1.Text = TabFormu1.Status.Name;
            FORMU2.Text = TabFormul1.Status.Name;
            //TB添加
            SHMM1.Text = TabMaterial5.Status.Name;
            SHMM2.Text = TabMaterial6.Status.Name;
            SHMM3.Text = TabMaterial7.Status.Name;
            SHMM4.Text = TabMaterial8.Status.Name;
            BOM3.Text = TabBom3.Status.Name;


            //默认第1个显示 Tabs被选中

            if (MM1.Visible)
            {
                MM1.CssClass = "tabs2";
                PP1.Visible = true;
                return;
            }

            if (MM2.Visible)
            {
                MM2.CssClass = "tabs2";
                PP2.Visible = true;
                return;
            }

            if (MM3.Visible)
            {
                MM3.CssClass = "tabs2";
                PP3.Visible = true;
                return;
            }
            if (MM4.Visible)
            {
                MM4.CssClass = "tabs2";
                PP18.Visible = true;
                return;
            }


            if (BOM1.Visible)
            {
                BOM1.CssClass = "tabs2";
                PP4.Visible = true;
                return;
            }
            if (BOM2.Visible)
            {
                BOM2.CssClass = "tabs2";
                PP8.Visible = true;
                return;
            }
            if (DD1.Visible)
            {
                DD1.CssClass = "tabs2";
                PP20.Visible = true;
                return;
            }
            if (DD2.Visible)
            {
                DD2.CssClass = "tabs2";
                PP21.Visible = true;
                return;
            }
            if (DD3.Visible)
            {
                DD3.CssClass = "tabs2";
                PP22.Visible = true;
                return;
            }
            if (INP1.Visible)
            {
                INP1.CssClass = "tabs2";
                PP5.Visible = true;
                return;
            }

            if (BAR1.Visible)
            {
                BAR1.CssClass = "tabs2";
                PP6.Visible = true;
                return;
            }

            if (CCC1.Visible)
            {
                CCC1.CssClass = "tabs2";
                PP7.Visible = true;
                return;
            }

            if (PR1.Visible)
            {
                PR1.CssClass = "tabs2";
                PP9.Visible = true;
                return;
            }

            if (PR2.Visible)
            {
                PR2.CssClass = "tabs2";
                PP10.Visible = true;
                return;
            }

            if (QUAL.Visible)
            {
                QUAL.CssClass = "tabs2";
                PP11.Visible = true;
                return;
            }

            if (QUAN.Visible)
            {
                QUAN.CssClass = "tabs2";
                PP12.Visible = true;
                return;
            }

            if (TJO1.Visible)
            {
                TJO1.CssClass = "tabs2";
                PP13.Visible = true;
                return;
            }

            if (PLALOG1.Visible)
            {
                PLALOG1.CssClass = "tabs2";
                PP14.Visible = true;
                return;

            }

            if (SCAN1.Visible)
            {
                SCAN1.CssClass = "tabs2";
                PP15.Visible = true;
                return;

            }

            if (FORMU1.Visible)
            {
                FORMU1.CssClass = "tabs2";
                PP16.Visible = true;
                return;

            }

            if (FORMU2.Visible)
            {
                FORMU2.CssClass = "tabs2";
                PP17.Visible = true;
                return;

            }
            if (this.HKNPL.Visible)
            {
                HKNPL.CssClass = "tabs2";
                PP23.Visible = true;
                return;
            }
            if (this.TWIP.Visible)
            {
                TWIP.CssClass = "tabs2";
                PP24.Visible = true;
                return;
            }
            //TB添加
            if (SHMM1.Visible)
            {
                SHMM1.CssClass = "tabs2";
                PP25.Visible = true;
                return;
            }
            if (SHMM2.Visible)
            {
                SHMM1.CssClass = "tabs2";
                PP26.Visible = true;
                return;
            }
            if (SHMM3.Visible)
            {
                SHMM3.CssClass = "tabs2";
                PP27.Visible = true;
                return;
            }
            if (SHMM4.Visible)
            {
                SHMM4.CssClass = "tabs2";
                PP28.Visible = true;
                return;
            }
            if (BOM3.Visible)
            {
                BOM3.CssClass = "tabs2";
                PP29.Visible = true;
                return;
            }
        }
        #endregion

        #region 方法 InitTabStatus
        private void InitTabStatus()
        {
            IList<mdc_Config> config = (mdc_Config.process == TaskAPI.Process & mdc_Config.step == TaskAPI.Step
                                     & (mdc_Config.action == Actions.SelectedValue | mdc_Config.action == "*")
                                     & (mdc_Config.department == Department | mdc_Config.department == "*")).List<mdc_Config>();

            TabCCC1.Status = new MDCTabStatus(config, "CCC1");
            TabMaterial1.Status = new MDCTabStatus(config, "MM1");
            TabMaterial2.Status = new MDCTabStatus(config, "MM2");
            TabMaterial3.Status = new MDCTabStatus(config, "MM3");
            TabMaterial4.Status = new MDCTabStatus(config, "MM4");
            TabBom1.Status = new MDCTabStatus(config, "BOM1");
            TabBom2.Status = new MDCTabStatus(config, "BOM2");
            TabInsPlan1.Status = new MDCTabStatus(config, "INP1");
            TabBarcode1.Status = new MDCTabStatus(config, "BAR1");

            TabGroup1.Status = new MDCTabStatus(config, "PR1");
            TabHierarchy1.Status = new MDCTabStatus(config, "PR2");
            TabInsQual1.Status = new MDCTabStatus(config, "QUAL");
            TabInsQuan1.Status = new MDCTabStatus(config, "QUAN");
            TabTJO1.Status = new MDCTabStatus(config, "TJO1");
            TabPlg1.Status = new MDCTabStatus(config, "PLALOG1");
            TabScan1.Status = new MDCTabStatus(config, "SCAN1");
            TabFormu1.Status = new MDCTabStatus(config, "FORMU1");
            TabFormul1.Status = new MDCTabStatus(config, "FORMU2");

            Detemination1_1.Status = new MDCTabStatus(config, "DD1");
            Detemination1_2.Status = new MDCTabStatus(config, "DD2");
            Detemination1_3.Status = new MDCTabStatus(config, "DD3");
            TabHKNpl1.Status = new MDCTabStatus(config, "HKNPL");
            TWTabInsPlan1.Status = new MDCTabStatus(config, "IP");
            TabMaterial5.Status = new MDCTabStatus(config, "SHMM1");
            TabMaterial6.Status = new MDCTabStatus(config, "SHMM2");
            TabMaterial7.Status = new MDCTabStatus(config, "SHMM3");
            TabMaterial8.Status = new MDCTabStatus(config, "SHMM4");
            TabBom3.Status = new MDCTabStatus(config, "BOM3");

            if (!TaskAPI.IsInitiate)
            {
                TabMaterial1.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial2.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial3.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial4.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial5.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial6.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial7.Status.SAP_Code = IsShowSAPCode.Text;
                TabMaterial8.Status.SAP_Code = IsShowSAPCode.Text;
            }
        }
        #endregion

        #region 方法 InitDistribute
        protected void InitDistribute()
        {
            if (TaskAPI.Process != "P-Plant Extend Application")
            {
                Distribute.Items.Clear();
                IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & mdc_Recipient.distribute != "*").List<mdc_Recipient>();
                SetVisible(rec_s.Count > 0, Distribute, Distribute_L);

                foreach (mdc_Recipient rec in rec_s)
                {
                    if (Distribute.Items.FindByValue(rec.Distribute) == null)
                    {
                        //Distribute.Items.Add(new ListItem((Distribute.Items.Count + 1).ToString() + ", " + rec.Distribute, rec.Distribute));
                        Distribute.Items.Add(new ListItem("" + rec.Distribute, rec.Distribute));
                    }
                }
            }

        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            //第一次加载完成后初始化各 Tabs 状态
            if (!IsLoaded)
            {
                Actions_SelectedIndexChanged(null, e);

                switch (TaskAPI.Process)
                {
                    case "TW NPL Application-DECO":
                    case "TW NPL Application-PKG":
                    case "NPL Master Data Application":
                        SetPackCodeTab(e);
                        break;
                    case "P-Plant Extend Application":
                        SetPackCodeTab(e);
                        break;
                    case "HK ADVE Code Application":
                        SetADVETAB(e);
                        break;
                    case "TW Inspection Plan Maintenance":
                        SetInsplanTAB(e);
                        break;
                    case "TW Raw Code Application":
                        SetRawTAB(e);
                        break;
                    case "TW SEFI Code Application":
                        SetSefiTAB(e);
                        break;
                    case "TW FINI Code Application":
                        SetSefiTAB(e);
                        break;
                }

                //if (TaskAPI.Process == "NPL Master Data Application") SetPackCodeTab(e);
                IsLoaded = true;
            }

            base.OnLoadComplete(e);
        }
        #endregion

        #region 方法 数据验证

        #region Code Selected
        private List<string> DataValidation()
        {
            List<Regular> regs = new List<Regular>();
            if (TaskAPI.Process == "PKG Sefi Code BOM Application" || TaskAPI.Process == "PKG Fini Code BOM Application")
            {
                //if (!Code_Selected.Checked && !BOM_Selected.Checked && Actions.SelectedValue == "Revision")
                if (!Code_Selected.Checked && !BOM_Selected.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "请选择需要新建或修改的选项：Code或BOM"));
                }
            }
            //if (TaskAPI.Process == "TW Raw Code Application")
            //{
            //    if (!Code_Selected.Checked && !BOM_Selected.Checked)
            //    {
            //        regs.Add(new Regular(RegularExp.NotEmpty, "", "請選擇Raw Code或Raw For Sale"));
            //    }
            //}


            if (TaskAPI.Process == "Sefi BomIP Application")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, (!Sefi_Bom.Checked && !INP.Checked ? "" : "NotBlank"), "Sefi Bom 或 INS.Plan 至少需要选择 1 个"));
                if (Sefi_Bom.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, NPL_Sefi_BOM.SelectedValue, "是否申请NPL Sefi BOM 必填"));
                }
            }
            if (TaskAPI.Process == "Formula Switch Process")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Product_Line.SelectedValue, "组别 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Try_Product.SelectedValue, "试产 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Change_KPL.SelectedValue, "是否变更KPL 必填"));

                if ((Product_Line.SelectedValue == "Woodcare" || Product_Line.SelectedValue == "HPC") && Distribute.SelectedValue == "SH")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "SH工厂不生产Woodcare或者HPC"));
                }
                if (Product_Line.SelectedValue == "Pre-deco" && Distribute.SelectedValue == "LF")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "LF工厂不生产Pre-deco"));
                }
            }

            if (TaskAPI.Process == "Fini Code Application")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Affect_APO.SelectedValue, "是否影响APO 必填"));
            }
            if (TaskAPI.Process == "QA Inspection Plan")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Change_Modification.SelectedValue, "Change Modification rule 必填"));
            }


            if ((TaskAPI.Process == "MTO Base Code Application" || TaskAPI.Process == "TJO Base Code Application") && Distribute.SelectedValue == "")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, "", "Please Select不能为空"));
            }
            //王航更改 2017.6.8号
            if (TaskAPI.Process == "TJO Base Code Application")
            {
                if ((TaskAPI.Step == "Fill in the request")&& (Assessment1.Option.Contains(new t_AssessmentOption("来样是否收到?", "3", true))))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "&nbsp;&nbsp;销售及快递信息为必填"));
                }
            }

            if ((TaskAPI.Process == "TW Sefi Bom-IP Maintenance" || TaskAPI.Process == "TW Pack Material Maintenance" || TaskAPI.Process == "TW ADVE Code Application" || TaskAPI.Process == "TW Trade Code Application-DECO" || TaskAPI.Process == "TW Fini Bom Maintenance" || TaskAPI.Process == "TW Raw Code Application" || TaskAPI.Process == "TW SEFI Code Application" || TaskAPI.Process == "TW FINI Code Application") && Distribute.SelectedValue == "")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, "", "Please Select不能为空:請選擇 DECO 或 PKG"));
            }
            if (TaskAPI.Process == "HK-TJO Base Code Application")
            {
                TextBox remark = (TextBox)Assessment1.FindControl("Remark");
                regs.Add(new Regular(RegularExp.NotEmpty, (remark.Text + "").Trim(), "备注信息必须填写"));

            }
            if (TaskAPI.Process == "ADVE Code Application")
            {
                if (TaskAPI.Step == "Fill in the request")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, Channel.SelectedValue, "Channel 必填"));
                }
            }
            if (TaskAPI.Process == "NPL Master Data Application")
            {
                if (TaskAPI.Step == "Fill in the request")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, Channel.SelectedValue, "Channel 必填"));
                }
                if (TaskAPI.Step == "Production Site Select")
                {
                    if (RadionList_NPL.Visible == true && RadionList_NPL.SelectedValue == "")
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, "", "MTO Project Retail三选必须选择一项"));
                    }
                    if (SH_Selected.Checked == false && SH_Selected.Visible == true && GZ_Selected.Checked == false && GZ_Selected.Visible == true && LF_Selected.Checked == false && LF_Selected.Visible == true)
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, "", "SH GZ LF 三选必须选择一项"));
                    }
                }
            }
            else
            {
                return Validation(regs);
            }
        #endregion

            return Validation(regs);
        }
        #endregion

        #region Distribute Actions
        protected void Distribute_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (TaskAPI.Process == "MTO Base Code Application")
            {
                this.DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial1.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial2.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial3.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial4.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial5.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial6.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial7.DMO1.DMO_DrpPriority.SelectedValue = "1";
                (Page as PMDC).TabMaterial8.DMO1.DMO_DrpPriority.SelectedValue = "1";
                SetEnable(false, DrpPriority);
            }
            if (TaskAPI.Process == "TW New Raw Material Creation" || TaskAPI.Process == "TW Pack Material Maintenance")
            {
                SetEnable(true, (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center);
                SetForeColor(Color.Orange, (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1_L);
                if (Distribute.SelectedValue == "DECO")
                {

                    (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center.SelectedValue = "D4239003";
                    if (TaskAPI.Process == "TW Pack Material Maintenance")
                    {
                        (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "K26";
                    }
                    else
                        (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "K25";

                }
                else if (Distribute.SelectedValue == "PKG")
                {
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center.SelectedValue = "P4239001";
                    if (TaskAPI.Process == "TW Pack Material Maintenance")
                        (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "K53";
                    else
                        (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "K52";
                }
                else
                {
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center.SelectedValue = "";
                    (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "";

                }
                SetEnable(false, (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center);
            }
            if (TaskAPI.Process == "TW Raw Code Application")
            {
                SetEnable(true, (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center);
                SetEnable(true, (Page as PMDC).TabMaterial2.Finance1.FIN_Profit_Center);
                if (Distribute.SelectedValue == "DECO")
                {
                    (Page as PMDC).TabMaterial1.Planning1.PLA_Plant.SelectedValue = "KT1P";
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center.SelectedValue = "D4239003";
                    (Page as PMDC).TabMaterial2.Planning1.PLA_Plant.SelectedValue = "KT1D";
                    (Page as PMDC).TabMaterial2.Finance1.FIN_Profit_Center.SelectedValue = "D4239003";
                    //(Page as PMDC).TabMaterial2.Logistics1.LOG_Stock_removal.SelectedValue = "U01-DECO";
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Delivering_plant.Text = "KT1D";
                    (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "K25";
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Delivering_plant.Text = "KT1D";
                    SetVisible(true, (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Hierarchy, (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Hierarchy_L);
                    //(Page as PMDC).TabMaterial2.Finance1.FIN_Profit_Center.SelectedValue = "D423904";
                }
                else if (Distribute.SelectedValue == "PKG")
                {
                    (Page as PMDC).TabMaterial1.Planning1.PLA_Plant.SelectedValue = "KT2P";
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center.SelectedValue = "P4239001";
                    (Page as PMDC).TabMaterial2.Planning1.PLA_Plant.SelectedValue = "KT2D";
                    (Page as PMDC).TabMaterial2.Finance1.FIN_Profit_Center.SelectedValue = "P4239001";
                    //(Page as PMDC).TabMaterial2.Logistics1.LOG_Stock_removal.SelectedValue = "U02-PKG";
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Delivering_plant.Text = "KT2D";
                    (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "K52";
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Delivering_plant.Text = "KT2D";
                    SetVisible(false, (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Hierarchy, (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Hierarchy_L);
                    //(Page as PMDC).TabMaterial2.Finance1.FIN_Profit_Center.SelectedValue = "P423901";
                }
                else
                {
                    (Page as PMDC).TabMaterial1.Planning1.PLA_Plant.SelectedValue = "";
                    (Page as PMDC).TabMaterial1.Finance1.FIN_Profit_Center.SelectedValue = "";
                    (Page as PMDC).TabMaterial2.Planning1.PLA_Plant.SelectedValue = "";
                    (Page as PMDC).TabMaterial2.Finance1.FIN_Profit_Center.SelectedValue = "";
                    //(Page as PMDC).TabMaterial2.Logistics1.LOG_Stock_removal.SelectedValue = "";
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Delivering_plant.Text = "";
                    (Page as PMDC).TabMaterial1.Technical1.TEC_Lab_Office_1.Text = "";
                    //(Page as PMDC).TabMaterial2.Technical1.TEC_Lab_Office_1.Text = "";
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Delivering_plant.Text = "";
                    SetVisible(false, (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Hierarchy, (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Hierarchy_L);
                }
            }
            if (TaskAPI.Process == "TW SEFI Code Application")
            {
                SetSefiTAB(e);
            }
            if (TaskAPI.Process == "TW FINI Code Application")
            {
                if (Distribute.SelectedValue == "PKG")
                {
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Group.Dialog_ID = "TW-0010";
                }
                else if (Distribute.SelectedValue == "DECO")
                {
                    (Page as PMDC).TabMaterial1.Marketing1.MKT_Product_Group.Dialog_ID = "TW-002";
                }
                else
                {
                    (Page as PMDC).TabMaterial2.Marketing1.MKT_Product_Group.Text = "";
                    (Page as PMDC).TabMaterial1.Marketing1.MKT_Product_Group.Text = "";
                }
                SetSefiTAB(e);

            }
            if (TaskAPI.Process == "TW Raw Code Application")
            {
                SetRawTAB(e);
            }
            if (TaskAPI.Process == "TW Fini Bom Maintenance")
            {
                if (Distribute.SelectedValue == "DECO")
                {
                    (Page as PMDC).TabBom1.TW_Plant.SelectedValue = "KT1P";
                }
                else if (Distribute.SelectedValue == "PKG")
                {
                    (Page as PMDC).TabBom1.TW_Plant.SelectedValue = "KT2P";
                }
                else
                {
                    (Page as PMDC).TabBom1.TW_Plant.SelectedValue = "";
                }
            }
            SetFiniBomType();
        }
        private void SetFiniBomType()
        {
            if (TaskAPI.Process == "NPL Master Data Application")
            {
                if (TabBom1.Visible) TabBom1.rd_FINI_1.SelectedIndex = Distribute.SelectedValue == "Woodcare" ? 1 : 0;
                if (TabBom2.Visible) TabBom2.rd_FINI_1.SelectedIndex = Distribute.SelectedValue == "Woodcare" ? 1 : 0;
                if (TabBom3.Visible) TabBom3.rd_FINI_1.SelectedIndex = Distribute.SelectedValue == "Woodcare" ? 1 : 0;

            }

            if (TaskAPI.Process == "P-Plant Extend Application")
            {
                if (TabBom1.Visible)
                {
                    if (Distribute.SelectedValue == "LF-Woodcare" || Distribute.SelectedValue == "GZ-Woodcare")
                    {
                        TabBom1.rd_FINI_1.SelectedIndex = 1;
                    }
                    else
                    {
                        TabBom1.rd_FINI_1.SelectedIndex = 0;
                    }

                    if (Distribute.SelectedValue == "LF-Woodcare" || Distribute.SelectedValue == "GZ-Woodcare")
                    {
                        TabBom2.rd_FINI_1.SelectedIndex = 1;
                    }
                    else
                    {
                        TabBom2.rd_FINI_1.SelectedIndex = 0;
                    }
                }

                // if (TabBom1.Visible) TabBom1.rd_FINI_1.SelectedIndex = Distribute.SelectedValue == "GZ-Woodcare" ? 1 : 0;

            }
        }
        protected void PackCode_Selected_CheckedChanged(object sender, EventArgs e)
        {
            if (TaskAPI.Process == "NPL Master Data Application" || TaskAPI.Process == "P-Plant Extend Application" || TaskAPI.Process == "TW NPL Application-DECO" || TaskAPI.Process == "TW NPL Application-PKG")
            {
                if (sender.ToString() == "Anthem.CheckBox") TaskAPI["IsPackCode"] = PackCode_Selected.Checked ? "1" : "0";
                MM1.Visible = PackCode_Selected.Checked && PackCode_Selected.Visible;
                SetPackCodeTab(e);
            }
            //if (TaskAPI.Process == "TW Raw Code Application")
            //{
            //    //PackCode_Selected.Checked = true;
            //    if (SefiCode_Selected.Checked)
            //    {
            //        //SefiCode_Selected.Checked = false;
            //        PackCode_Selected.Checked = false;
            //    }
            //    MM1.Visible = PackCode_Selected.Checked && PackCode_Selected.Visible;
            //    SetPackCodeTab(e);
            //}
        }
        protected void SefiCode_Selected_CheckedChanged(object sender, EventArgs e)
        {
            if (TaskAPI.Process == "NPL Master Data Application" || TaskAPI.Process == "P-Plant Extend Application" || TaskAPI.Process == "HK NPL Master Application" || TaskAPI.Process == "TW NPL Application-PKG" || TaskAPI.Process == "TW NPL Application-DECO")
            {
                if (sender.ToString() == "Anthem.CheckBox") TaskAPI["IsSefiCode"] = SefiCode_Selected.Checked ? "1" : "0";
                MM2.Visible = SefiCode_Selected.Checked && SefiCode_Selected.Visible;
                SetPackCodeTab(e);

            }
            //if (TaskAPI.Process == "TW Raw Code Application")
            //{
            //    //SefiCode_Selected.Checked = true;
            //    if (PackCode_Selected.Checked)
            //    {
            //        //PackCode_Selected.Checked = false;
            //        SefiCode_Selected.Checked = false;
            //    }
            //    MM2.Visible = SefiCode_Selected.Checked && SefiCode_Selected.Visible;
            //    SetPackCodeTab(e);
            //}
        }
        protected void IP_Selected_CheckedChanged(object sender, EventArgs e)
        {
            string id = ((CheckBox)sender).ID.ToString();
            if (TaskAPI.Process == "TW Inspection Plan Maintenance")
            {
                LinkButton s = new LinkButton();
                if (!IP_Selected.Checked && !Qual_Selected.Checked && !Quan_Selected.Checked)
                {
                    ((CheckBox)sender).Checked = true;
                }
                if (id == "IP_Selected" && ((CheckBox)sender).Checked)
                {
                    TaskAPI["IsIpCode"] = this.IP_Selected.Checked ? "1" : "0";
                    s.ID = "TWIP";
                }
                else if (id == "Qual_Selected" && ((CheckBox)sender).Checked)
                {
                    TaskAPI["IsQualCode"] = this.Qual_Selected.Checked ? "1" : "0";
                    s.ID = "QUAL";
                }
                else if (id == "Quan_Selected" && ((CheckBox)sender).Checked)
                {
                    TaskAPI["IsQuanCode"] = this.Quan_Selected.Checked ? "1" : "0";
                    s.ID = "QUAN";
                }
                else
                {

                    if (Qual_Selected.Checked && Qual_Selected.Visible)
                    {
                        s.ID = "QUAL";
                    }
                    else if (Quan_Selected.Checked && Quan_Selected.Visible)
                    {
                        s.ID = "QUAN";
                    }
                    else if (IP_Selected.Checked && IP_Selected.Visible)
                    {
                        s.ID = "TWIP";
                    }
                }
                TWIP.Visible = IP_Selected.Checked && IP_Selected.Visible;
                QUAL.Visible = Qual_Selected.Checked && Qual_Selected.Visible;
                QUAN.Visible = Quan_Selected.Checked && Quan_Selected.Visible;
                MM_Click(s, e);
            }
        }
        private void SetPackCodeTab(EventArgs e)
        {
            MM1.Visible = PackCode_Selected.Checked && PackCode_Selected.Visible;
            MM2.Visible = SefiCode_Selected.Checked && SefiCode_Selected.Visible;
            LinkButton s = new LinkButton();
            s.ID = PackCode_Selected.Checked && PackCode_Selected.Visible ? "MM1" : MM2.Visible ? "MM2" : "MM3";
            if (TaskAPI.Process == "HK NPL Master Application")
            {
                if (!PackCode_Selected.Checked && !SefiCode_Selected.Checked)
                {
                    s.ID = "HKNPL";
                }
            }
            MM_Click(s, e);
        }
        #endregion
        #endregion

        #region 事件 rd_HK_ADVE_Biz_Type
        protected void rd_HK_ADVE_Biz_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetADVETAB(e);
            //if (rd_FINI_1.SelectedIndex == 1)
            //{
            //    gv_FINI_2.Columns[17].Visible = true;
            //    gv_FINI_2.Columns[16].Visible = true;rd_HK_ADVE_Biz_Type
            //}
            //else
            //{
            //    gv_FINI_2.Columns[17].Visible = false;
            //    gv_FINI_2.Columns[16].Visible = false;
            //}
        }

        private void SetADVETAB(EventArgs e)
        {
            if (rd_HK_ADVE_Biz_Type.SelectedValue == "0")
            {
                MM1.Visible = true;
                MM2.Visible = false;

                LinkButton s = new LinkButton();
                s.ID = "MM1";
                MM_Click(s, e);
            }
            else
            {
                MM1.Visible = false;
                MM2.Visible = true;

                LinkButton s = new LinkButton();
                s.ID = "MM2";
                MM_Click(s, e);
            }
        }

        private void SetInsplanTAB(EventArgs e)
        {

            QUAN.Visible = Quan_Selected.Checked && Quan_Selected.Visible;
            QUAL.Visible = Qual_Selected.Checked && Qual_Selected.Visible;
            TWIP.Visible = IP_Selected.Checked && IP_Selected.Visible;
            LinkButton s = new LinkButton();
            s.ID = QUAL.Visible ? "QUAL" : QUAN.Visible ? "QUAN" : "TWIP";
            MM_Click(s, e);

        }
        #endregion

        #region 事件 rd_Raw_Code
        protected void rd_Raw_Code_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetRawTAB(e);
        }
        private void SetRawTAB(EventArgs e)
        {
            if (rd_Raw_Code.SelectedValue == "0")
            {
                MM1.Visible = true;
                MM2.Visible = false;

                LinkButton s = new LinkButton();
                s.ID = "MM1";
                MM_Click(s, e);
            }
            else
            {
                MM1.Visible = false;
                MM2.Visible = true;

                LinkButton s = new LinkButton();
                s.ID = "MM2";
                MM_Click(s, e);
            }
        }
        #endregion

        #region 事件 Cancel
        protected void Cancel_Click(object sender, EventArgs e)
        {
            TaskAPI["Cancel"] = "1";
            bool flg = TaskAPI.Send();
            Cancel.Visible = false;
            ClearStoreAPI();
            Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
        }
        #endregion

        #region 事件 SetSefiTAB
        private void SetSefiTAB(EventArgs e)
        {
            if (Distribute.SelectedValue == "DECO")
            {
                MM1.Visible = true;
                MM2.Visible = false;

                LinkButton s = new LinkButton();
                s.ID = "MM1";
                MM_Click(s, e);
            }
            else if (Distribute.SelectedValue == "PKG")
            {
                MM1.Visible = false;
                MM2.Visible = true;

                LinkButton s = new LinkButton();
                s.ID = "MM2";
                MM_Click(s, e);
            }
            else
            {
                MM1.Visible = true;
                MM2.Visible = true;

                LinkButton s = new LinkButton();
                s.ID = "MM1";
                s.ID = "MM2";
                MM_Click(s, e);
            }
        }
        #endregion

        //private void SetNPL(EventArgs e)
        //{

        //   if (TaskAPI.Step == "Pro PD Plant Extend Project"||TaskAPI.Step == "Pro PD Plant Extend MTO"||TaskAPI.Step == "Pro PD Plant Extend Retail")
        //      {
        //          SHMM2.Visible = SH_Selected.Checked & SH_Selected.Visible;
        //          LinkButton s= new LinkButton();
        //          s.ID = "SHMM2";
        //          MM_Click(s,e);
        //      }
        //   if (TaskAPI.Step == "Pack Extend")
        //   {
        //       SHMM1.Visible = SH_Selected.Checked & SH_Selected.Visible;
        //       LinkButton s = new LinkButton();
        //       s.ID = "SHMM1";
        //       MM_Click(s,e);
        //   }
        //}

        protected void tDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (TaskAPI.IsBeginStep && TaskAPI.Process == "P-Plant Extend Application" && TaskAPI.IsAllowSubmit)
            {
                Distribute.Items.Clear();
                IList<string> distribute_ = new List<string>();
                distribute_ = (m_Production.step == "Technical" & m_Production.production_Type == Production.SelectedValue).List<m_Production>().Select(p => p.Distribute).Distinct().ToList();
                foreach (var ds in distribute_)
                {

                    Distribute.Items.Add(new ListItem(ds, ds));

                }
                if (Production.SelectedValue != "Retail-Emulsion")
                {
                    Distribute.SelectedValue = Production.SelectedValue;
                }
            }
        }

        #region NPL获取工厂状态
        public DataTable GetSelect(int Incident, string Process)
        {
            string SQL = "select top 1 IsSH_Selected,IsGZ_Selected,IsLF_Selected,IsRadionList_NPL  from mdc_MDC where process='" + Process + "' and Incident='" + Incident + "' order by Time desc";
            TaskDB taskdb = new TaskDB();
            taskdb.Storage("oleDB");
            DataTable dt = taskdb.Query(SQL);
            return dt;
        }
        #endregion

        #region 事件SH_Selected
        protected void SH_Selected_CheckedChanged(object sender, EventArgs e)
        {

            if (TaskAPI.Process == "NPL Master Data Application")
            {
                RadionList_NPL.Visible = SH_Selected.Checked && SH_Selected.Visible == true;
            }
        }
        #endregion

        #region 抓取Emial功能
        private List<string> GetEmailByWinId(List<string> winIds)
        {
            if (winIds == null || winIds.Count <= 0) return null;
            const string sql = @"SELECT EMAIL FROM CLIENTS WHERE USERNAME IN ({0})";
            var ds = Storage.Context2.ExecuteDataSet(new Command(string.Format(sql, string.Join(",", winIds.ToArray()))));
            if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
            var ret = new List<string>();
            foreach (System.Data.DataRow r in ds.Tables[0].Rows)
            {
                var email = r[0];
                if (email == null || email == DBNull.Value || ret.Contains(email as string)) continue;
                ret.Add(email as string);
            }
            return ret;
        }
        #endregion

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                {

                    drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                    drpT.SelectedValue = o.ToString();

                    return;
                }

                drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                drpT.SelectedIndex = 0;

            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region 数据验证
        private List<string> DataValidations()
        {
            List<Regular> regs = new List<Regular>();
            if (TaskAPI.Process == "TW New Raw Material Creation")
            {
                if (Distribute.SelectedValue == null || Distribute.SelectedValue == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " Please Select 不能为空"));
                }
            }
            if (TaskAPI.Process == "P-Plant Extend Application")
            {
                if (Distribute.SelectedValue == null || Distribute.SelectedValue == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " 请选择产品的分类，Please Select不能为空"));
                }
                if (Production.SelectedValue == null || Production.SelectedValue == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " 请选择产品类型，Production不能为空"));
                }
            }
            return Validation(regs);
        }
        #endregion

    }
}
